結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー momoyuumomoyuu
提出日時 2023-10-22 17:48:06
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,227 bytes
コンパイル時間 1,340 ms
コンパイル使用メモリ 117,200 KB
実行使用メモリ 9,224 KB
最終ジャッジ日時 2023-10-22 17:48:10
合計ジャッジ時間 3,750 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 38 ms
5,564 KB
testcase_05 AC 89 ms
7,132 KB
testcase_06 AC 108 ms
8,124 KB
testcase_07 AC 49 ms
5,884 KB
testcase_08 AC 68 ms
6,616 KB
testcase_09 AC 106 ms
7,808 KB
testcase_10 AC 88 ms
7,156 KB
testcase_11 AC 70 ms
6,692 KB
testcase_12 AC 96 ms
7,616 KB
testcase_13 AC 70 ms
6,972 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
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);
    vector<vector<int>> g(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]--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int sum = 0;
    int all = 0;
    int c = 0;
    vector<int> vis(n,0);

    for(int i = 0;i<n;i++){
        if(vis[i]) continue;
        if(uf.size(i)==1&&s.count(i)==0) continue;
        int tmp = 0;
        vector<int> que;
        que.push_back(i);
        vis[i]++;
        for(int j = 0;j<que.size();j++){
            int ni = que[j];
            if(cnt[j]>0) tmp += cnt[j];
            for(auto&to:g[j]){
                if(vis[to]) continue;
                vis[to]++;
                que.push_back(to);
            }
        }
        tmp = max(0,tmp-1);
        all += tmp;

        c++;
    }
    cout<<all+c-1<<endl;

}
0