QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84443 | #5651. Parmigiana With Seafood | Bird | WA | 43ms | 12868kb | C++14 | 760b | 2023-03-06 15:03:29 | 2023-03-06 15:04:53 |
Judging History
answer
#include<bits/stdc++.h>
#include<queue>
#define N 100000
using namespace std;
int n,ans,deep[N+5],fa[N+5];
vector<int> e[N+5],v[N+5];
inline void dfs(int x)
{
if(!(deep[x]=deep[fa[x]]^1)) ans=max(ans,x);
for(int y:e[x]) if(y!=fa[x]) fa[y]=x,dfs(y);
sort(v[x].begin(),v[x].end(),greater<int>());
if(x!=n && deep[x] && v[x].size()>1) ans=max(ans,v[x][1]);
if(x==n && v[x].size()>2) ans=max(ans,v[x][2]);
v[fa[fa[x]]].push_back(v[x].empty() || x>v[x][0]?x:v[x][0]);
}
int main()
{
scanf("%d",&n);
for(int i=1,u,v;i<n;++i)
{
scanf("%d %d",&u,&v);
e[u].push_back(v);
e[v].push_back(u);
}
if(!(n&1)) return printf("%d\n",n),0;
for(int i=n;i;--i) if(e[i].size()==1) {ans=i;break;}
dfs(n),printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 8184kb
input:
4 1 2 1 3 1 4
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 3ms
memory: 8288kb
input:
5 1 5 5 3 3 4 4 2
output:
3
result:
ok single line: '3'
Test #3:
score: -100
Wrong Answer
time: 43ms
memory: 12868kb
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:
99996
result:
wrong answer 1st lines differ - expected: '99925', found: '99996'