結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー momoyuumomoyuu
提出日時 2023-10-22 17:43:20
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 912 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 115,772 KB
実行使用メモリ 12,460 KB
最終ジャッジ日時 2023-10-22 17:43:24
合計ジャッジ時間 3,954 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 30 ms
4,348 KB
testcase_05 AC 91 ms
4,348 KB
testcase_06 AC 76 ms
4,672 KB
testcase_07 AC 38 ms
4,348 KB
testcase_08 AC 48 ms
4,348 KB
testcase_09 AC 76 ms
4,508 KB
testcase_10 AC 66 ms
4,348 KB
testcase_11 AC 52 ms
4,348 KB
testcase_12 AC 71 ms
4,348 KB
testcase_13 AC 50 ms
4,436 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 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<iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include<set>

using namespace std;
using ll = long long;

#include<atcoder/dsu>

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin>>n>>m;
    vector<int> cnt(n,0);
    set<int> s;
    atcoder::dsu uf(n);
    for(int i = 0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        uf.merge(u,v);
        s.insert(u);
        s.insert(v);
        cnt[u]++;
        cnt[v]--;
    }
    int sum = 0;
    int all = 0;
    for(int i = 0;i<n;i++) {
        sum += cnt[i];
        if(cnt[i]>0) all += cnt[i];
    }
    all = max(0,all-1);
    int c = 0;
    set<int> vis;
    for(int i = 0;i<n;i++){
        int ni = uf.leader(i);
        if(vis.count(ni)) continue;
        vis.insert(ni);
        if(uf.size(ni)==1&&s.count(ni)==0) continue;
        c++;
    }
    cout<<all+c-1<<endl;

}
0