QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#439317#8575. Three Person Tree Gamereal_sigma_team#WA 18ms3572kbC++231.5kb2024-06-11 19:29:112024-06-11 19:29:13

Judging History

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

  • [2024-06-11 19:29:13]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:3572kb
  • [2024-06-11 19:29:11]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        int n, a, b, c;
        cin >> n >> a >> b >> c;
        --a, --b, --c;
        vector<vector<int>> gr(n);
        for (int i = 1, u, v; i < n; ++i) {
            cin >> u >> v;
            --u, --v;
            gr[u].push_back(v);
            gr[v].push_back(u);
        }
        vector<int> dist(n), par(n);
        auto dfs = [&](auto self, int v, int p, int d) -> void {
            dist[v] = d;
            par[v] = p;
            for (int u: gr[v])
                if (u != p)
                    self(self, u, v, d + 1);
        };
        dfs(dfs, a, a, 0);
        int lb = b, lc = c;
        while (lb != lc) {
            if (dist[lb] < dist[lc])
                lc = par[lc];
            else
                lb = par[lb];
        }
        int l = lb;
        dfs(dfs, l, l, 0);
        int da = dist[a], db = dist[b], dc = dist[c];
        bool aw = false, bw = false, cw = false;
        if (da < db && da < dc)
            aw = true;
        if (db + 1 < da && db < dc)
            bw = true;
        if (dc + 1 < da && dc + 1 < db)
            cw = true;
        assert(aw + bw + cw <= 1);
        if (aw)
            cout << 'A';
        else if (bw)
            cout << 'B';
        else if (cw)
            cout << 'C';
        else
            cout << "DRAW";
        cout << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3540kb

input:

2
3
1 2 3
2 1
3 1
4
1 2 3
1 4
2 4
3 4

output:

A
DRAW

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 18ms
memory: 3572kb

input:

10000
20
2 12 1
16 15
3 2
16 17
14 13
11 12
9 8
10 9
18 17
6 5
18 19
13 12
5 4
7 6
20 19
14 15
3 4
11 10
1 2
8 7
20
12 13 1
18 13
12 11
19 15
17 16
10 14
4 2
15 11
6 5
3 2
4 13
20 8
11 9
3 7
14 16
5 8
5 4
9 6
10 3
1 2
17
2 17 15
9 10
5 4
9 8
2 11
6 7
8 7
13 4
2 3
6 15
5 6
17 8
2 1
3 4
16 7
14 5
3 12...

output:

A
B
C
B
DRAW
C
A
A
A
DRAW
DRAW
B
B
DRAW
DRAW
A
DRAW
DRAW
DRAW
DRAW
DRAW
DRAW
A
DRAW
A
DRAW
B
DRAW
C
A
A
A
DRAW
B
DRAW
C
DRAW
A
A
DRAW
DRAW
DRAW
DRAW
DRAW
DRAW
C
DRAW
A
DRAW
DRAW
B
DRAW
A
DRAW
DRAW
DRAW
DRAW
C
DRAW
DRAW
A
A
DRAW
DRAW
DRAW
B
B
B
A
DRAW
B
DRAW
A
A
DRAW
B
A
A
DRAW
DRAW
DRAW
DRAW
DRAW
DR...

result:

wrong answer 11th lines differ - expected: 'C', found: 'DRAW'