結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー cho435cho435
提出日時 2023-08-04 22:32:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 565 bytes
コンパイル時間 5,027 ms
コンパイル使用メモリ 260,296 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-04-22 20:49:26
合計ジャッジ時間 6,743 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 44 ms
5,376 KB
testcase_05 AC 86 ms
5,376 KB
testcase_06 AC 96 ms
5,376 KB
testcase_07 AC 55 ms
5,376 KB
testcase_08 AC 65 ms
5,376 KB
testcase_09 AC 102 ms
5,376 KB
testcase_10 AC 95 ms
5,376 KB
testcase_11 AC 72 ms
5,376 KB
testcase_12 AC 102 ms
5,376 KB
testcase_13 AC 68 ms
5,376 KB
testcase_14 WA -
testcase_15 AC 1 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
	int n,m;
	cin>>n>>m;
	vector<int> in(n,0),ou(n,0);
	atcoder::dsu uf(n);
	rep(i,m){
		int u,v;
		cin>>u>>v;
		u--; v--;
		ou.at(u)++;
		in.at(v)++;
		uf.merge(u,v);
	}
	ll ans=0;
	rep(i,n){
		if(in.at(i)>ou.at(i)) ans+=in.at(i)-ou.at(i);
	}
	map<int,int> mp;
	rep(i,n) mp[uf.leader(i)]++;
	ans-=2;
	for(auto [ld,nm]:mp){
		if(nm==1&&in.at(ld)==0){
			continue;
		}
		ans+=2;
	}
	if(ans>0) ans--;
	cout<<ans<<endl;
}
0