QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#94835#5672. Connectivity Problempedroteosousa#WA 3ms4564kbC++20666b2023-04-07 23:02:172023-04-07 23:02:18

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-07 23:02:18]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:4564kb
  • [2023-04-07 23:02:17]
  • 提交

answer

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

const int N = 112345;
int p[N], w[N];

void init() {
    for (int i = 0; i < N; i++) {
        w[p[i] = i] = 1;
    }
}

int find(int a) {
    return (p[a] == a) ? a : (p[a] = find(p[a]));
}

void join(int a, int b) {
    if ((a = find(a)) == (b = find(b))) return;
    if (w[a] < w[b]) swap(a, b);
    w[a] += w[b];
    p[b] = a;
}

int main() {
    int n; scanf("%d", &n);
    init();
    for (int i = 0; i < n; i++) {
        int p, q; scanf("%d %d", &p, &q); p--; q--;
        if (find(p) == find(q)) {
            printf("Y\n");
        } else {
            printf("N\n");
            join(p, q);
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 4336kb

input:

12
3 4
4 9
8 1
2 3
5 6
2 9
5 9
7 3
4 8
5 6
1 8
6 1

output:

N
N
N
N
N
Y
N
N
N
Y
Y
Y

result:

ok 12 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 4564kb

input:

100
26 39
2 21
4 17
2 16
12 19
27 0
8 43
10 12
6 29
5 9
19 32
13 47
13 36
3 6
13 18
9 40
11 40
29 16
7 24
10 35
19 41
6 24
28 21
26 35
23 47
2 30
19 17
10 6
22 6
15 25
19 11
2 8
11 25
14 23
27 1
1 16
16 0
23 34
2 25
10 17
3 35
23 37
13 0
22 7
27 29
15 13
10 5
18 40
28 46
19 0
23 40
4 46
19 3
20 39
1...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
Y
N
Y
N
Y
Y
Y
N
N
Y
Y
Y
Y
Y
N
Y
Y
Y
Y
N
Y
Y
Y
Y
Y
Y
Y
N
N
N
Y
N
N
Y
Y
Y
Y
Y
Y
Y
Y
Y
N
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y

result:

wrong answer 35th lines differ - expected: 'N', found: 'Y'