QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84539#4511. Wonderland Chasewangzhe_04770 9605ms42380kbC++232.7kb2023-03-06 15:45:302023-03-06 15:46:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 15:46:02]
  • 评测
  • 测评结果:0
  • 用时:9605ms
  • 内存:42380kb
  • [2023-03-06 15:45:30]
  • 提交

answer

// Google Code Jam 2022 World Finals
// Problem A. Wonderland Chase
#include <bits/stdc++.h>

using LL = long long;
using ULL = unsigned LL;

constexpr ULL E(long double x, int y) {
    while (y--) x *= 10;
    return x;
}
constexpr ULL SIZE(long double x, int y) {return E(x, y) + 5;}

const int inf32 = E(1, 9) + 5;
const LL inf64 = E(1, 18) + 5;

bool vis[SIZE(1, 5)];
std::multiset<int> graph[SIZE(1, 5)];
int n, m, s, t, deg[SIZE(1, 5)], dis[2][SIZE(1, 5)];

int main() {
    int data_count;
    scanf("%d", &data_count);
    for (int data = 1; data <= data_count; data++) {
        scanf("%d%d%d%d", &n, &m, &s, &t);
        for (int i = 1; i <= n; i++) {
            deg[i] = 0;
            vis[i] = false;
            dis[0][i] = dis[1][i] = -1;
            graph[i].clear();
        }
        for (int i = 1; i <= m; i++) {
            int x, y;
            scanf("%d%d", &x, &y);
            graph[x].insert(y);
            graph[y].insert(x);
            deg[x]++;
            deg[y]++;
        }
        std::queue<int> que;
        for (int i = 1; i <= n; i++)
            if (deg[i] == 1)
                que.push(i);
        while (que.size()) {
            int u = que.front();
            que.pop();
            vis[u] = true;
            for (int v : graph[u])
                if (--deg[v] == 1)
                    que.push(v);
        }
        que.push(s);
        dis[0][s] = 0;
        while (que.size()) {
            int u = que.front();
            que.pop();
            for (int v : graph[u]) {
                if (dis[0][v] != -1) continue;
                dis[0][v] = dis[0][u] + 1;
                que.push(v);
            }
        }
        que.push(t);
        dis[1][t] = 0;
        while (que.size()) {
            int u = que.front();
            que.pop();
            for (int v : graph[u]) {
                if (dis[1][v] != -1) continue;
                dis[1][v] = dis[1][u] + 1;
                que.push(v);
            }
        }
        if (dis[1][s] == -1)
            printf("Case #%d: SAFE\n", data);
        else {
            bool flag = false;
            for (int i = 1; i <= n; i++) {
                if (!vis[i] && dis[0][i] < dis[1][i]) {
                    printf("Case #%d: SAFE\n", data);
                    flag = true;
                }
            }
            if (!flag) {
                int max = 0;
                for (int i = 1; i <= n; i++) {
                    if (dis[0][i] < dis[1][i])
                        max = std::max(max, dis[1][i]);
                }
                printf("Case #%d: %d\n", data, 2 * max);
            }
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 8668kb

input:

100
2 1 1 2
1 2
3 3 1 2
1 3
1 2
2 3
6 6 5 1
1 4
5 6
3 4
3 6
2 3
1 2
6 6 2 4
4 5
1 4
2 3
2 5
1 6
5 6
6 6 2 3
1 3
3 4
2 6
2 5
4 5
1 5
6 5 5 3
2 5
3 4
1 2
3 6
4 6
6 5 1 6
1 4
1 2
5 6
3 5
2 4
30 29 11 5
9 21
25 28
14 20
13 30
21 28
5 18
5 23
8 22
10 30
4 8
7 24
16 26
13 26
12 18
22 23
11 16
3 11
2 17
1 ...

output:

Case #1: 2
Case #2: SAFE
Case #3: 8
Case #4: 6
Case #5: SAFE
Case #6: SAFE
Case #7: SAFE
Case #8: SAFE
Case #9: SAFE
Case #10: 8
Case #11: 4
Case #12: 2
Case #13: SAFE
Case #14: 2
Case #15: 10
Case #16: 10
Case #17: 6
Case #18: 2
Case #19: 28
Case #20: 28
Case #21: 18
Case #22: 2
Case #23: 58
Case #...

result:

wrong answer 27th lines differ - expected: 'Case #27: SAFE', found: 'Case #26: SAFE'

Test #2:

score: 0
Wrong Answer
time: 9605ms
memory: 42380kb

input:

100
100000 99999 32832 52005
67463 96972
10280 86580
12146 44520
41541 86634
46936 64223
22701 46291
9093 80967
52512 77386
51062 58931
2092 55026
2096 2384
85102 92986
39914 66949
33370 68952
41576 58836
27668 33997
5843 30705
44415 57721
15188 28706
23340 55082
20335 90872
16029 80328
4656 74633
8...

output:

Case #1: SAFE
Case #2: SAFE
Case #3: 8
Case #4: 4
Case #5: 2
Case #6: SAFE
Case #7: 2
Case #8: 39998
Case #9: 39998
Case #10: 19192
Case #11: 2
Case #12: 99998
Case #13: 99998
Case #14: 16776
Case #15: 2
Case #16: 199998
Case #17: 199998
Case #18: 141806
Case #19: SAFE
Case #19: SAFE
Case #19: SAFE
...

result:

wrong answer 20th lines differ - expected: 'Case #20: SAFE', found: 'Case #19: SAFE'