QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84683 | #5651. Parmigiana With Seafood | sinsop90 | WA | 13ms | 9188kb | C++14 | 747b | 2023-03-06 16:54:35 | 2023-03-06 16:54:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int head[maxn], dis[maxn], ans, t1, t2, tot, n;
struct node {
int v, pre;
}e[maxn << 1];
void add(int u, int v) {
e[++ tot].v = v;
e[tot].pre = head[u];
head[u] = tot;
}
void dfs(int now, int f) {
for(int i = head[now];i;i = e[i].pre) {
int v = e[i].v;
if(v == f) continue;
dis[v] = dis[now] ^ 1;
dfs(v, now);
}
}
int main() {
scanf("%d", &n);
if(n % 2 == 0) {
printf("%d\n", n);
return 0;
}
for(int i = 1, u, v;i < n;i++) {
scanf("%d%d", &u, &v);
add(u, v), add(v, u);
}
dfs(n, 0);
for(int i = 1;i < n;i++) {
if(dis[i]) ans = max(ans, i);
else t2 = t1, t1 = i;
}
printf("%d\n", max(ans, min(t1, t2)));
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 5604kb
input:
4 1 2 1 3 1 4
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 2ms
memory: 5600kb
input:
5 1 5 5 3 3 4 4 2
output:
3
result:
ok single line: '3'
Test #3:
score: -100
Wrong Answer
time: 13ms
memory: 9188kb
input:
99999 81856 39633 81856 94012 99999 43062 99946 220 81856 46131 99933 36505 99939 35662 99952 70971 99999 3275 99938 58416 99976 66658 99991 87922 81856 80992 99933 6392 99951 41047 99970 54115 81856 38150 99934 73554 81856 64578 81856 18576 99951 67996 99938 84479 81856 39617 99999 18664 99946 2505...
output:
99997
result:
wrong answer 1st lines differ - expected: '99925', found: '99997'