QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84435 | #5651. Parmigiana With Seafood | Appleblue17 | WA | 29ms | 10328kb | C++14 | 701b | 2023-03-06 14:57:35 | 2023-03-06 14:57:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,ans;
vector <int> G[N];
int in[N];
int omx,emx[N];
int dep[N];
void dfs(int u,int fa){
if(dep[u]%2) omx=max(omx,u);
else emx[u]=u;
int mx=0,mx2=0;
for(int v: G[u]){
if(v==fa) continue;
dep[v]=dep[u]+1;
dfs(v,u);
if(emx[v]>mx) mx2=mx,mx=emx[v];
else if(emx[v]>mx2) mx2=emx[v];
}
ans=max(ans,mx2);
}
int main(){
cin>>n;
if(n%2==0) return cout<<n,0;
for(int i=2;i<=n;i++){
int u,v; scanf("%d%d",&u,&v);
G[u].push_back(v);
G[v].push_back(u);
in[u]++,in[v]++;
}
for(int i=1;i<=n;i++)
if(in[i]==1) ans=max(ans,i);
dfs(n,0);
ans=max(ans,omx);
cout<<ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6568kb
input:
4 1 2 1 3 1 4
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 3ms
memory: 6080kb
input:
5 1 5 5 3 3 4 4 2
output:
3
result:
ok single line: '3'
Test #3:
score: -100
Wrong Answer
time: 29ms
memory: 10328kb
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'