結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー t98slidert98slider
提出日時 2023-08-05 06:31:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 3,900 ms
コンパイル使用メモリ 230,032 KB
実行使用メモリ 15,408 KB
最終ジャッジ日時 2023-08-17 18:47:37
合計ジャッジ時間 5,966 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 16 ms
4,376 KB
testcase_05 AC 30 ms
4,376 KB
testcase_06 AC 33 ms
4,380 KB
testcase_07 AC 19 ms
4,380 KB
testcase_08 AC 22 ms
4,380 KB
testcase_09 AC 34 ms
4,376 KB
testcase_10 AC 31 ms
4,380 KB
testcase_11 AC 24 ms
4,376 KB
testcase_12 AC 33 ms
4,380 KB
testcase_13 AC 24 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 23 ms
15,408 KB
testcase_20 AC 6 ms
5,540 KB
testcase_21 AC 13 ms
9,496 KB
testcase_22 AC 20 ms
14,112 KB
testcase_23 AC 21 ms
13,624 KB
testcase_24 AC 17 ms
11,980 KB
testcase_25 AC 16 ms
11,180 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 22 ms
14,616 KB
testcase_28 AC 18 ms
12,280 KB
testcase_29 AC 6 ms
4,884 KB
testcase_30 AC 10 ms
8,128 KB
testcase_31 AC 23 ms
14,920 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 9 ms
6,860 KB
testcase_34 AC 5 ms
4,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, u, v, ans = -1, s;
    cin >> n >> m;
    atcoder::dsu uf(n);
    vector<int> a(n), b(n);
    while(cin >> u >> v){
        uf.merge(--u, --v);
        if(u == v) b[u] = 1;
        a[u]++, a[v]--;
    }
    for(auto vec : uf.groups()){
    	if(vec.size() == 1){
    		ans += b[vec[0]];
    		continue;
    	}
        s = 0;
        for(auto v : vec) if(a[v] > 0) s += a[v];
        ans += max(1, s);
    }
    cout << ans << '\n';
}
0