PKU 3180 The Cow Prom
- 強連結成分分解
- グループの定義が問題から読み取りにくい
- 実はちゃんとわかっていない
- Spaghetti Source - 強連結成分分解 http://www.prefield.com/algorithm/graph/strongly_connected_components.html
int main() { int N, M; cin >> N >> M; Graph g(N + 1); REP(m, M) { int src, dst; cin >> src >> dst; g[src].push_back(Edge(src, dst, 0)); } vector<vector<int> > scc; stronglyConnectedComponents(g, scc); int answer = 0; REP(i, scc.size()) { if (scc[i].size() > 1) { ++answer; } } cout << answer << endl; }