結果

問題 No.1813 Magical Stones
ユーザー 沙耶花沙耶花
提出日時 2022-01-14 21:57:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 865 bytes
コンパイル時間 4,167 ms
コンパイル使用メモリ 265,200 KB
実行使用メモリ 17,908 KB
最終ジャッジ日時 2023-08-12 19:26:45
合計ジャッジ時間 7,885 ms
ジャッジサーバーID
(参考情報)
judge2 / judge7
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 13 ms
9,764 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 21 ms
5,280 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 14 ms
9,776 KB
testcase_15 AC 124 ms
13,700 KB
testcase_16 AC 125 ms
13,592 KB
testcase_17 AC 126 ms
17,908 KB
testcase_18 AC 127 ms
13,528 KB
testcase_19 AC 125 ms
13,652 KB
testcase_20 AC 126 ms
13,960 KB
testcase_21 AC 126 ms
13,680 KB
testcase_22 AC 126 ms
13,900 KB
testcase_23 AC 126 ms
13,676 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 13 ms
4,512 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 82 ms
10,392 KB
testcase_28 AC 116 ms
13,412 KB
testcase_29 AC 99 ms
11,692 KB
testcase_30 AC 96 ms
11,308 KB
testcase_31 AC 112 ms
12,720 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 5 ms
4,376 KB
testcase_35 AC 18 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 39 ms
6,112 KB
testcase_38 AC 14 ms
7,464 KB
testcase_39 AC 75 ms
9,740 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 6 ms
4,376 KB
testcase_42 AC 19 ms
4,380 KB
testcase_43 AC 10 ms
4,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001

int main(){
	
	int n,m;
	cin>>n>>m;
	
	scc_graph S(n);
	vector<int> a(m),b(m);
	rep(i,m){
		cin>>a[i]>>b[i];
		a[i]--;b[i]--;
		S.add_edge(a[i],b[i]);
	}
	
	vector<int> pos(n);
	auto s = S.scc();
	if(s.size()==1){
		cout<<0<<endl;
		return 0;
	}
	rep(i,s.size()){
		rep(j,s[i].size()){
			pos[s[i][j]] = i;
		}
	}
	
	vector<int> x(s.size()),y(s.size());
	
	rep(i,m){
		int X = pos[a[i]],Y = pos[b[i]];
		if(X==Y)continue;
		x[X]++;
		y[Y]++;
	}
	
	int ans = 0;
	
	{
		int sum = 0;
		rep(i,x.size())if(x[i]==0)sum ++;
		ans = max(ans,sum);
	}
	{
		int sum = 0;
		rep(i,y.size())if(y[i]==0)sum ++;
		ans = max(ans,sum);
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}
0