結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー ManjushriMitraManjushriMitra
提出日時 2024-06-15 12:23:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 2,283 ms
コンパイル使用メモリ 178,688 KB
実行使用メモリ 11,192 KB
最終ジャッジ日時 2024-06-15 12:23:56
合計ジャッジ時間 5,802 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 91 ms
11,192 KB
testcase_04 AC 14 ms
7,296 KB
testcase_05 AC 60 ms
7,808 KB
testcase_06 AC 56 ms
9,728 KB
testcase_07 AC 70 ms
7,552 KB
testcase_08 AC 59 ms
10,452 KB
testcase_09 AC 81 ms
9,088 KB
testcase_10 AC 91 ms
10,624 KB
testcase_11 AC 76 ms
9,912 KB
testcase_12 AC 51 ms
8,376 KB
testcase_13 AC 24 ms
5,504 KB
testcase_14 AC 49 ms
7,296 KB
testcase_15 AC 45 ms
5,376 KB
testcase_16 AC 95 ms
10,112 KB
testcase_17 AC 25 ms
5,376 KB
testcase_18 AC 43 ms
8,576 KB
testcase_19 AC 8 ms
6,656 KB
testcase_20 AC 50 ms
5,376 KB
testcase_21 AC 29 ms
6,272 KB
testcase_22 AC 32 ms
5,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,m,n) for(int i=m; i<n; ++i)
#define repl(i,m,n) for(ll i=m; i<n; ++i)

vector<vector<int>> Graph;
vector<bool> visited;

void dfs(int v, int &cnt){
    visited[v] = true;
    cnt++;
    for(int nv : Graph[v]){
        if(visited[nv]) continue;
        dfs(nv, cnt);
    }
}

int main(){
    int N, M;
    cin >> N >> M;

    Graph.resize(2*N);
    rep(i, 0, M){
        int A, B;
        cin >> A >> B;
        Graph[A-1].push_back(B-1);
        Graph[B-1].push_back(A-1);
    }

    visited.assign(2*N, false);
    int cnt = 0, ans = N;
    for(int i = 0; i < 2*N; ++i){
        if(visited[i]) continue;
        dfs(i, cnt);
        ans -= cnt / 2;
        cnt = 0;
    }
    cout << ans << endl;

    return 0;
}
0