QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278796#5672. Connectivity Problemdat#RE 1ms3900kbC++171.1kb2023-12-07 20:45:062023-12-07 20:45:07

Judging History

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

  • [2023-12-07 20:45:07]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3900kb
  • [2023-12-07 20:45:06]
  • 提交

answer

#ifdef LOCAL
#include "precompiled_headers.h"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

int n;
vector <int> adj[10007];

bool bfs(int u, int f) {
    queue <int> q;
    q.push(u);
    vector <int> colors(10007, 0);
    colors[u] = 1;

    while (q.size()) {
        int s = q.front();
        q.pop();

        for (int v : adj[s]) {
            if (colors[v] == 0) {
                q.push(v);
                colors[v] = 1;
                if (v == f) {
                    return true;
                }
            }
        }
    }
    return false;
}

int main() {
    std::ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n;

//    adj.resize(n);
    int q, p;
    while (n--) {
        cin >> q >> p;
        q -= 1;
        p -= 1;
        if (bfs(q, p)) {
            cout << "Y";
        }
        else {
            cout << "N";
        }
        cout << "\n";
        adj[q].push_back(p);
        adj[p].push_back(q);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3900kb

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
Runtime Error

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:


result: