結果

問題 No.1813 Magical Stones
ユーザー MasKoaTSMasKoaTS
提出日時 2022-01-09 16:31:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 1,660 bytes
コンパイル時間 4,739 ms
コンパイル使用メモリ 259,388 KB
実行使用メモリ 21,380 KB
最終ジャッジ日時 2024-04-26 19:49:42
合計ジャッジ時間 10,037 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 16 ms
12,176 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 25 ms
6,400 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 15 ms
12,176 KB
testcase_15 AC 158 ms
17,260 KB
testcase_16 AC 158 ms
17,048 KB
testcase_17 AC 160 ms
21,380 KB
testcase_18 AC 159 ms
17,136 KB
testcase_19 AC 163 ms
17,388 KB
testcase_20 AC 165 ms
17,268 KB
testcase_21 AC 164 ms
17,132 KB
testcase_22 AC 172 ms
17,388 KB
testcase_23 AC 161 ms
17,264 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 16 ms
5,504 KB
testcase_26 AC 6 ms
5,376 KB
testcase_27 AC 104 ms
12,884 KB
testcase_28 AC 139 ms
15,344 KB
testcase_29 AC 126 ms
14,428 KB
testcase_30 AC 117 ms
13,684 KB
testcase_31 AC 144 ms
16,076 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 6 ms
5,376 KB
testcase_35 AC 20 ms
5,376 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 43 ms
6,652 KB
testcase_38 AC 17 ms
9,336 KB
testcase_39 AC 95 ms
12,540 KB
testcase_40 AC 4 ms
5,376 KB
testcase_41 AC 7 ms
5,376 KB
testcase_42 AC 22 ms
5,376 KB
testcase_43 AC 12 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <math.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define ite(i, a) for(auto& i : a)
#define all(x) x.begin(), x.end()
#define lb lower_bound
#define ub upper_bound
#define lbi(A, x) (ll)(lb(all(A), x) - A.begin())
#define ubi(A, x) (ll)(ub(all(A), x) - A.begin())
using ll = long long;
using Pair = pair<int, int>;
template <class T>	using V = vector<T>;
template <class T>	using VV = V<V<T> >;
const ll INF = 1000000000000000001;
const int inf = 1001001001;
const ll mod = 1000000007;
const ll MOD = 998244353;
template <class T>  inline V<T> getList(int n) { V<T> res(n); rep(i, 0, n) { cin >> res[i]; }return res; }
template <class T>  inline VV<T> getGrid(int m, int n) { VV<T> res(m, V<T>(n)); rep(i, 0, m) { res[i] = getList<T>(n); }return res; }
inline V<int> dtois(string& s) { V<int> vec = {}; for (auto& e : s) { vec.push_back(e - '0'); } return vec; }


int main(void) {
	int n, m;	cin >> n >> m;
	VV<int> route(n, V<int>(0));
	scc_graph g(n);

	rep(i, 0, m) {
		int a, b;	cin >> a >> b;	a--;	b--;
		route[a].push_back(b);
		g.add_edge(a, b);
	}

	VV<int> scc = g.scc();
	if (scc.size() == 1) {
		cout << 0 << endl;
		return 0;
	}
	V<int> group(n);
	rep(i, 0, scc.size()) {
		ite(p, scc[i]) {
			group[p] = i;
		}
	}

	V<int> source(scc.size(), 1);	V<int> sink(scc.size(), 1);
	rep(i, 0, n) {
		ite(j, route[i]) {
			int s = group[i];	int t = group[j];
			if (s != t) {
				sink[s] = source[t] = 0;
			}
		}
	}

	int s = 0, t = 0;
	ite(i, source) {
		s += i;
	}
	ite(i, sink) {
		t += i;
	}

	cout << max(s, t) << endl;
	return 0;
}
0