結果

問題 No.1813 Magical Stones
ユーザー MasKoaTS
提出日時 2022-01-12 22:41:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,650 bytes
コンパイル時間 4,399 ms
コンパイル使用メモリ 256,664 KB
最終ジャッジ日時 2025-01-27 10:39:31
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 23 WA * 17
権限があれば一括ダウンロードができます

ソースコード

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];
			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