QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#439338 | #8575. Three Person Tree Game | real_sigma_team# | WA | 1ms | 3596kb | C++23 | 1.7kb | 2024-06-11 19:48:06 | 2024-06-11 19:48:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
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);
}
bool f = false;
for (int i : gr[a])
if (i == c) {
cout << 'A';
f = true;
}
if (f)
continue;
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 + 1 <= dc)
aw = true;
if (db <= da && db < dc)
bw = true;
if (dc < da && dc < 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: 0
Wrong Answer
time: 1ms
memory: 3596kb
input:
2 3 1 2 3 2 1 3 1 4 1 2 3 1 4 2 4 3 4
output:
ADRAW
result:
wrong answer 1st lines differ - expected: 'A', found: 'ADRAW'