結果
問題 |
No.679 不思議マーケット
|
ユーザー |
|
提出日時 | 2020-08-02 17:30:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 998 bytes |
コンパイル時間 | 1,094 ms |
コンパイル使用メモリ | 83,960 KB |
最終ジャッジ日時 | 2025-01-12 13:28:46 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <queue> void solve() { int n; std::cin >> n; std::vector<int> rem(n, 0); std::vector<std::vector<int>> to(n); { int m; std::cin >> m; while (m--) { int g; std::cin >> g; --g; auto& r = rem[g]; std::cin >> r; for (int j = 0; j < r; ++j) { int x; std::cin >> x; to[--x].push_back(g); } } } std::queue<int> que; for (int v = 0; v < n; ++v) { if (rem[v] == 0) que.push(v); } while (!que.empty()) { int v = que.front(); que.pop(); for (auto g : to[v]) { if (--rem[g] == 0) que.push(g); } } std::cout << std::count(rem.begin(), rem.end(), 0) << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }