結果

問題 No.1813 Magical Stones
ユーザー MasKoaTSMasKoaTS
提出日時 2021-11-28 13:29:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,338 bytes
コンパイル時間 5,064 ms
コンパイル使用メモリ 265,748 KB
実行使用メモリ 21,360 KB
最終ジャッジ日時 2023-09-23 07:09:10
合計ジャッジ時間 8,851 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 16 ms
13,836 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 27 ms
7,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 16 ms
13,824 KB
testcase_15 AC 163 ms
18,184 KB
testcase_16 AC 159 ms
18,232 KB
testcase_17 WA -
testcase_18 AC 166 ms
18,036 KB
testcase_19 AC 165 ms
17,984 KB
testcase_20 AC 165 ms
18,220 KB
testcase_21 AC 165 ms
18,020 KB
testcase_22 AC 162 ms
18,020 KB
testcase_23 AC 162 ms
18,268 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 17 ms
5,868 KB
testcase_26 AC 7 ms
4,376 KB
testcase_27 AC 105 ms
14,040 KB
testcase_28 AC 144 ms
15,048 KB
testcase_29 AC 130 ms
15,076 KB
testcase_30 AC 122 ms
14,316 KB
testcase_31 AC 150 ms
17,384 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 6 ms
4,380 KB
testcase_35 WA -
testcase_36 AC 4 ms
4,376 KB
testcase_37 AC 42 ms
6,048 KB
testcase_38 AC 19 ms
10,228 KB
testcase_39 AC 99 ms
14,308 KB
testcase_40 AC 5 ms
4,380 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 12 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//嘘解法(SCC 後、場合分けなし)

#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define max(p, q) ((p) > (q) ? (p) : (q))
using namespace std;
using namespace atcoder;
using ll = long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;


int bool_sum(V<bool>& a) {
	int res = 0;
	rep(i, 0, a.size()) {
		if (a[i]) {
			res++;
		}
	}
	return res;
}


VV<int> SCC_to_DAG(int n, VV<int>& route, VV<int>& scc) {
	VV<int> dag(scc.size(), V<int>(0));
	V<int> group(n);
	rep(i, 0, scc.size()) {
		rep(j, 0, scc[i].size()) {
			group[scc[i][j]] = i;
		}
	}

	rep(i, 0, n) {
		rep(j, 0, route[i].size()) {
			int a = group[i];	int b = group[route[i][j]];
			if (a != b) {
				dag[a].push_back(b);
			}
		}
	}

	return dag;
}


int main(void) {
	int n, m;	cin >> n >> m;

	VV<int> route(n, V<int>(0));
	scc_graph ss(n);
	rep(i, 0, m) {
		int a, b;   cin >> a >> b;
		a--;	b--;
		ss.add_edge(a, b);
		route[a].push_back(b);
	}

	VV<int> scc = ss.scc();

	VV<int> dag = SCC_to_DAG(n, route, scc);
	int ds = dag.size();
	V<bool> source(ds, true);	V<bool> sink(ds, true);
	rep(i, 0, ds) {
		rep(j, 0, dag[i].size()) {
			source[i] = sink[dag[i][j]] = false;
		}
	}
	int ans = max(bool_sum(source), bool_sum(sink));

	cout << ans << endl;
	return 0;
}
0