結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー 👑 獅子座じゃない人獅子座じゃない人
提出日時 2023-07-12 14:54:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 767 bytes
コンパイル時間 1,773 ms
コンパイル使用メモリ 176,940 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2024-05-05 01:22:14
合計ジャッジ時間 3,694 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 40 ms
5,376 KB
testcase_05 AC 82 ms
5,376 KB
testcase_06 AC 83 ms
5,504 KB
testcase_07 AC 49 ms
5,376 KB
testcase_08 AC 58 ms
5,376 KB
testcase_09 AC 91 ms
5,504 KB
testcase_10 AC 89 ms
5,376 KB
testcase_11 AC 65 ms
5,376 KB
testcase_12 AC 89 ms
5,376 KB
testcase_13 AC 68 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 22 ms
15,616 KB
testcase_20 AC 6 ms
5,504 KB
testcase_21 AC 11 ms
9,600 KB
testcase_22 AC 19 ms
14,208 KB
testcase_23 AC 18 ms
13,824 KB
testcase_24 AC 16 ms
12,032 KB
testcase_25 AC 14 ms
11,520 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 21 ms
14,848 KB
testcase_28 AC 17 ms
12,364 KB
testcase_29 AC 6 ms
5,376 KB
testcase_30 AC 10 ms
8,192 KB
testcase_31 AC 20 ms
15,104 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 7 ms
6,912 KB
testcase_34 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <atcoder/dsu>
using namespace atcoder;

int main(void)
{
    int n,m;
    cin >> n >> m;
    vector<int> u(m);
    vector<int> v(m);
    dsu g(n);
    vector<int> outdeg(n);
    vector<int> indeg(n);
    for(int i=0;i<m;++i){
        cin >> u[i] >> v[i];
        --u[i];
        --v[i];
        g.merge(u[i],v[i]);
        ++outdeg[u[i]];
        ++indeg[v[i]];
    }
    auto ccs=g.groups();
    int ans=-1;
    for(auto cc: ccs){
        int tmp=0;
        bool ok=false;
        for(auto p: cc){
            if(indeg[p]>0){
                ok=true;
            }
            tmp+=abs(outdeg[p]-indeg[p]);
        }
        tmp/=2;
        ans+=max(tmp-1,0)+ok;
    }
    cout << ans << endl;
    return 0;
}
0