Submission #421285


Source Code Expand

#include <iostream>
using namespace std;

int main() {
    int N, Q;
    cin >> N >> Q;
    auto parent = new int[N+1];
    for (int i = 0; i < N+1; ++i) {
        parent[i] = i;
    }
    int P, A, B;
    for (int q = 0; q < Q; ++q) {
        scanf("%d%d%d", &P, &A, &B);
        if (P == 0) {
            int a = A;
            while (parent[a] != a) {
                int beforeParent = parent[a];
                parent[a] = B;
                a = beforeParent;
            }
            parent[a] = B;
        }
        else {
            int aroot = parent[A];
            while (parent[aroot] != aroot) {
                aroot = parent[aroot];
            }
            int broot = parent[B];
            while (parent[broot] != broot) {
                broot = parent[broot];
            }
            cout << (aroot == broot?"Yes":"No") << endl;
        }
    }

    return 0;
}

Submission Info

Submission Time
Task B - Union Find
User urasa
Language C++11 (GCC 4.9.2)
Score 0
Code Size 925 Byte
Status TLE
Exec Time 5034 ms
Memory 1312 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:13:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &P, &A, &B);
                                    ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 1
AC × 17
TLE × 2
Set Name Test Cases
Sample 00_sample_01.txt
All 00_sample_01.txt, subtask_01_01.txt, subtask_01_02.txt, subtask_01_03.txt, subtask_01_04.txt, subtask_01_05.txt, subtask_01_06.txt, subtask_01_07.txt, subtask_01_08.txt, subtask_01_09.txt, subtask_01_10.txt, subtask_01_11.txt, subtask_01_12.txt, subtask_01_13.txt, subtask_01_14.txt, subtask_01_15.txt, subtask_01_16.txt, subtask_01_17.txt, subtask_01_18.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 29 ms 796 KiB
subtask_01_01.txt AC 348 ms 924 KiB
subtask_01_02.txt AC 28 ms 1300 KiB
subtask_01_03.txt AC 566 ms 916 KiB
subtask_01_04.txt AC 693 ms 1312 KiB
subtask_01_05.txt AC 55 ms 928 KiB
subtask_01_06.txt AC 54 ms 1308 KiB
subtask_01_07.txt AC 543 ms 928 KiB
subtask_01_08.txt AC 673 ms 1188 KiB
subtask_01_09.txt AC 25 ms 920 KiB
subtask_01_10.txt AC 25 ms 1304 KiB
subtask_01_11.txt AC 533 ms 800 KiB
subtask_01_12.txt AC 555 ms 1184 KiB
subtask_01_13.txt AC 451 ms 920 KiB
subtask_01_14.txt AC 27 ms 1228 KiB
subtask_01_15.txt AC 540 ms 804 KiB
subtask_01_16.txt AC 582 ms 1312 KiB
subtask_01_17.txt TLE 5034 ms 1308 KiB
subtask_01_18.txt TLE 5033 ms 1192 KiB