結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー bortikbortik
提出日時 2023-08-16 03:01:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,117 bytes
コンパイル時間 1,978 ms
コンパイル使用メモリ 214,156 KB
実行使用メモリ 12,572 KB
最終ジャッジ日時 2024-05-03 12:38:00
合計ジャッジ時間 3,486 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 58 ms
12,572 KB
testcase_04 AC 14 ms
8,320 KB
testcase_05 AC 27 ms
7,680 KB
testcase_06 AC 36 ms
11,040 KB
testcase_07 AC 28 ms
7,040 KB
testcase_08 AC 41 ms
12,088 KB
testcase_09 AC 37 ms
8,832 KB
testcase_10 AC 50 ms
11,972 KB
testcase_11 AC 44 ms
11,060 KB
testcase_12 AC 30 ms
9,344 KB
testcase_13 AC 14 ms
6,940 KB
testcase_14 AC 27 ms
8,064 KB
testcase_15 AC 18 ms
6,940 KB
testcase_16 AC 43 ms
10,628 KB
testcase_17 AC 11 ms
6,940 KB
testcase_18 AC 29 ms
9,576 KB
testcase_19 AC 12 ms
7,680 KB
testcase_20 AC 20 ms
6,940 KB
testcase_21 AC 18 ms
6,944 KB
testcase_22 AC 14 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, n, a) for (int i = (int)(n); i >= (int)(a); i--)

void solve(){
    int n,m; cin >> n >> m;
    vector<vector<int>> adj(2*n);
    rep(i,0,m){
        int x,y; cin >> x >> y;
        x--;y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    vector<int> color(2*n);
    iota(color.begin(), color.end(), 1);
    vector<bool> seen(n*2, false);
    stack<int> todo;
    rep(i,0,2*n) todo.push(i);
    while(!todo.empty()){
        int x = todo.top();
        todo.pop();
        if(seen[x]) continue;
        seen[x] = true;
        for(int u: adj[x]){
            color[u] = color[x];
            todo.push(u);
        }
    }

    int ans = 0;
    sort(color.begin(), color.end());
    int s = 1;
    rep(i,1,2*n){
        if(color[i] != color[i-1]){
            ans += s % 2;
            s = 1;
        } else s++;
    }
    ans += s % 2;
    cout << ans/2;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();

    return 0;
}
0