QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#313654 | #5667. Meeting Places | blln | WA | 1ms | 3740kb | C++11 | 773b | 2024-01-24 21:56:50 | 2024-01-24 21:56:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m, o = 0, x, y, F[N], Dep[N], num[N], last[N], nxt[N];
int main() {
queue<int> tot;
tot.push(1);
scanf("%d %d", &n, &m);
for (int i = 2; i <= n; i++) scanf("%d", &F[i]), o++, nxt[o] = i, last[o] = num[F[i]], num[F[i]] = o;
while (!tot.empty()) {
x = tot.front();
tot.pop();
for (int i = num[x]; i; i = last[i]) Dep[nxt[i]] = Dep[x] + 1, tot.push(nxt[i]);
}
while (m--) {
scanf("%d %d", &x, &y);
while (x != y) {
if (Dep[x] > Dep[y])
x = F[x];
else if (Dep[x] < Dep[y])
y = F[y];
else
x = F[x], y = F[y];
}
printf("%d\n", x);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3740kb
input:
100 23 213
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
wrong answer 1st numbers differ - expected: '1319350480.8007326', found: '0.0000000', error = '1.0000000'