結果

問題 No.679 不思議マーケット
ユーザー kagasankagasan
提出日時 2020-04-19 20:44:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,598 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 172,164 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 00:11:53
合計ジャッジ時間 2,806 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 7 ms
6,940 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

vector<ll>path[555];
vector<ll>rev[555];
ll cnt[555];


int main(){

    ll N, M;
    cin >> N >> M;
    rep(i, M){
        ll g, r;
        cin >> g >> r;
        rep(j, r){
            ll h;
            cin >> h;
            path[g].push_back(h);
            rev[h].push_back(g);
        }
    }
    ll ans = 0;
    priority_queue<P, vector<P>, greater<P> >Q;
    rep1(i, N){
        cnt[i] = path[i].size();
        Q.push(P(cnt[i], i));
    }    
    while(!Q.empty()){
        ll sz = Q.top().first;
        ll idx = Q.top().second;
        Q.pop();
        if(sz)break;
        if(cnt[idx] < 0)continue;
        cnt[idx] = -1;
        ans++;
        for(auto from : rev[idx]){
            cnt[from]--;
            Q.push(P(cnt[from], from));
        }    
    }
    cout << ans << endl;
    
    return 0;
}
0