結果

問題 No.1813 Magical Stones
ユーザー 沙耶花沙耶花
提出日時 2022-01-14 21:57:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 865 bytes
コンパイル時間 4,877 ms
コンパイル使用メモリ 266,920 KB
実行使用メモリ 18,028 KB
最終ジャッジ日時 2024-04-30 14:31:33
合計ジャッジ時間 8,379 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 15 ms
9,964 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 23 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 15 ms
9,972 KB
testcase_15 AC 142 ms
13,800 KB
testcase_16 AC 140 ms
13,800 KB
testcase_17 AC 140 ms
18,028 KB
testcase_18 AC 142 ms
13,896 KB
testcase_19 AC 138 ms
13,932 KB
testcase_20 AC 138 ms
13,932 KB
testcase_21 AC 139 ms
13,932 KB
testcase_22 AC 138 ms
13,928 KB
testcase_23 AC 138 ms
13,812 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 14 ms
6,944 KB
testcase_26 AC 6 ms
6,940 KB
testcase_27 AC 89 ms
10,304 KB
testcase_28 AC 129 ms
13,388 KB
testcase_29 AC 109 ms
11,700 KB
testcase_30 AC 105 ms
11,400 KB
testcase_31 AC 124 ms
12,868 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 6 ms
6,940 KB
testcase_35 AC 20 ms
6,940 KB
testcase_36 AC 4 ms
6,940 KB
testcase_37 AC 43 ms
6,940 KB
testcase_38 AC 16 ms
7,612 KB
testcase_39 AC 81 ms
10,056 KB
testcase_40 AC 5 ms
6,940 KB
testcase_41 AC 6 ms
6,940 KB
testcase_42 AC 21 ms
6,940 KB
testcase_43 AC 12 ms
6,944 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