提出 #39442373


ソースコード 拡げる




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

void dfs(int u, vector<vector<int>> &adj, vector<bool> &vis) {
    vis[u] = true;
    // cnt_v++;
    // cnt_e += adj[u].size();
    for (int v : adj[u]) {
        if (!vis[v]) {
            dfs(v, adj, vis);
        }
    }
}

bool same(int n, int m, vector<vector<int>> &adj, vector<bool> &vis) {
    for(int i = 1; i <= n; i++) {
        if(!vis[i]) {
            dfs(i, adj, vis);
            int c = 0;
            for(auto x : vis) {
                if(x == true) {
                    c ++;
                }
            }

            int e = 0;
            for(int j = 1; j <= n; j++) {
                if(vis[j]) {
                    e = e + adj[j].size();
                }
            }

            c = c * 2;
            if(c != e) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj(n + 1);
    vector<bool> vis(n + 1, false);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    // bool ok = true;
    // for (int i = 1; i <= n; i++) {
    //     if (!vis[i]) {
    //         int cnt_v = 0, cnt_e = 0;
    //         dfs(i, cnt_v, cnt_e);
    //         if (cnt_v != cnt_e / 2) {
    //             ok = false;
    //             break;
    //         }
    //     }
    // }

    if (same(n, m, adj, vis)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

提出情報

提出日時
問題 D - Unicyclic Components
ユーザ Sudhir87
言語 C++ (GCC 9.2.1)
得点 400
コード長 1637 Byte
結果 AC
実行時間 153 ms
メモリ 23436 KiB

コンパイルエラー

./Main.cpp: In function ‘bool same(int, int, std::vector<std::vector<int> >&, std::vector<bool>&)’:
./Main.cpp:19:22: warning: unused parameter ‘m’ [-Wunused-parameter]
   19 | bool same(int n, int m, vector<vector<int>> &adj, vector<bool> &vis) {
      |                  ~~~~^

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 61
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 02_one_00.txt, 02_one_01.txt, 02_one_02.txt, 02_one_03.txt, 02_one_04.txt, 02_one_05.txt, 02_one_06.txt, 02_one_07.txt, 02_one_08.txt, 02_one_09.txt, 02_one_10.txt, 02_one_11.txt, 02_one_12.txt, 02_one_13.txt, 03_two_00.txt, 03_two_01.txt, 03_two_02.txt, 03_two_03.txt, 03_two_04.txt, 03_two_05.txt, 03_two_06.txt, 03_two_07.txt, 03_two_08.txt, 03_two_09.txt, 03_two_10.txt, 03_two_11.txt, 04_many_00.txt, 04_many_01.txt, 04_many_02.txt, 04_many_03.txt, 04_many_04.txt, 04_many_05.txt, 04_many_06.txt, 04_many_07.txt, 04_many_08.txt, 04_many_09.txt, 04_many_10.txt, 04_many_11.txt, 05_hand_00.txt, 05_hand_01.txt, 99_hack_00.txt, 99_hack_01.txt, 99_hack_02.txt, 99_hack_03.txt, 99_hack_04.txt, 99_hack_05.txt, 99_hack_06.txt, 99_hack_07.txt, 99_hack_08.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 7 ms 3484 KiB
00_sample_01.txt AC 2 ms 3564 KiB
00_sample_02.txt AC 2 ms 3564 KiB
01_rnd_00.txt AC 3 ms 3564 KiB
01_rnd_01.txt AC 2 ms 3500 KiB
01_rnd_02.txt AC 54 ms 5120 KiB
01_rnd_03.txt AC 2 ms 3616 KiB
01_rnd_04.txt AC 2 ms 3452 KiB
01_rnd_05.txt AC 69 ms 5548 KiB
01_rnd_06.txt AC 8 ms 7920 KiB
01_rnd_07.txt AC 9 ms 7776 KiB
01_rnd_08.txt AC 153 ms 15892 KiB
02_one_00.txt AC 3 ms 3428 KiB
02_one_01.txt AC 2 ms 3544 KiB
02_one_02.txt AC 2 ms 3608 KiB
02_one_03.txt AC 2 ms 3512 KiB
02_one_04.txt AC 2 ms 3492 KiB
02_one_05.txt AC 2 ms 3484 KiB
02_one_06.txt AC 2 ms 3404 KiB
02_one_07.txt AC 115 ms 12780 KiB
02_one_08.txt AC 115 ms 12716 KiB
02_one_09.txt AC 114 ms 12788 KiB
02_one_10.txt AC 116 ms 12644 KiB
02_one_11.txt AC 113 ms 12736 KiB
02_one_12.txt AC 115 ms 12768 KiB
02_one_13.txt AC 114 ms 12660 KiB
03_two_00.txt AC 114 ms 12768 KiB
03_two_01.txt AC 116 ms 12536 KiB
03_two_02.txt AC 114 ms 12680 KiB
03_two_03.txt AC 120 ms 12820 KiB
03_two_04.txt AC 116 ms 12756 KiB
03_two_05.txt AC 113 ms 12656 KiB
03_two_06.txt AC 120 ms 12744 KiB
03_two_07.txt AC 120 ms 12760 KiB
03_two_08.txt AC 123 ms 12632 KiB
03_two_09.txt AC 128 ms 12748 KiB
03_two_10.txt AC 128 ms 12704 KiB
03_two_11.txt AC 122 ms 12700 KiB
04_many_00.txt AC 76 ms 10072 KiB
04_many_01.txt AC 77 ms 10108 KiB
04_many_02.txt AC 76 ms 10100 KiB
04_many_03.txt AC 75 ms 10016 KiB
04_many_04.txt AC 116 ms 12540 KiB
04_many_05.txt AC 116 ms 12716 KiB
04_many_06.txt AC 116 ms 12636 KiB
04_many_07.txt AC 115 ms 12500 KiB
04_many_08.txt AC 107 ms 12192 KiB
04_many_09.txt AC 107 ms 12292 KiB
04_many_10.txt AC 110 ms 12212 KiB
04_many_11.txt AC 112 ms 12412 KiB
05_hand_00.txt AC 3 ms 3560 KiB
05_hand_01.txt AC 111 ms 23436 KiB
99_hack_00.txt AC 2 ms 3476 KiB
99_hack_01.txt AC 3 ms 3472 KiB
99_hack_02.txt AC 2 ms 3416 KiB
99_hack_03.txt AC 2 ms 3604 KiB
99_hack_04.txt AC 2 ms 3488 KiB
99_hack_05.txt AC 2 ms 3420 KiB
99_hack_06.txt AC 2 ms 3508 KiB
99_hack_07.txt AC 2 ms 3492 KiB
99_hack_08.txt AC 2 ms 3560 KiB