QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#613124 | #8239. Mysterious Tree | mojimoon | WA | 1ms | 3880kb | C++14 | 1.9kb | 2024-10-05 13:36:16 | 2024-10-05 13:36:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
/*
interactive problem
judge if the tree is a star or a chain
a star has 1 node with degree n-1 and the rest with degree 1
a chain has 2 nodes with degree 1 and the rest with degree 2
max number of queries allowed is n/2+4
*/
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int u = -1, v = -1, r;
for (int i = 1; i < n; i+= 2) {
printf("? %d %d\n", i, i + 1);
fflush(stdout);
scanf("%d", &r);
if (r == 1) {
u = i;
v = i + 1;
break;
}
}
if (u == -1) {
printf("! 1\n"); // chain
fflush(stdout);
continue;
}
int p1 = -1, p2 = -1;
// choose 2 arbitrary nodes other than u and v
for (int i = 1; i <= n; i++) {
if (i != u && i != v) {
if (p1 == -1) {
p1 = i;
} else {
p2 = i;
break;
}
}
}
int r1, r2;
printf("? %d %d\n", p1, u);
fflush(stdout);
scanf("%d", &r1);
printf("? %d %d\n", p1, v);
fflush(stdout);
scanf("%d", &r2);
if (!r1 && !r2) {
printf("! 1\n"); // chain
fflush(stdout);
} else {
if (r2) {
swap(u, v);
}
printf("? %d %d\n", p2, u);
fflush(stdout);
scanf("%d", &r1);
if (r1) {
printf("! 2\n"); // star
fflush(stdout);
} else {
printf("! 1\n"); // chain
fflush(stdout);
}
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3800kb
input:
2 4 1 0 1 0 4 0 1 1 0 1
output:
? 1 2 ? 3 1 ? 3 2 ? 4 2 ! 1 ? 1 2 ? 3 4 ? 1 3 ? 1 4 ? 2 3 ! 2
result:
ok Correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3880kb
input:
87 13 0 0 0 0 0 1 0 1 1 15 0 0 0 0 0 0 1 1 0 1 7 0 0 0
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 1 11 ? 1 12 ? 2 12 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 13 14 ? 1 13 ? 1 14 ? 2 13 ! 2 ? 1 2 ? 3 4 ? 5 6 ! 1
result:
wrong answer Wrong prediction (test case 3)