QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#407271 | #5651. Parmigiana With Seafood | dykw | WA | 18ms | 10444kb | C++20 | 869b | 2024-05-08 13:50:18 | 2024-05-08 13:50:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
signed main(){cin.tie(0)->sync_with_stdio(0);
int n;cin>>n;vector<vector<int>>e(n);
if(n%2==0)return cout<<n,0;
for(int i=0;i<n-1;++i){
int u,v;cin>>u>>v;--u,--v;
e[u].push_back(v),e[v].push_back(u);
}
vector<int>d(n),t(n,-1);
auto dfs=[&](auto&self,int u,int f)->void{
if(d[u]%2==0)t[u]=u;
for(int v:e[u])if(v!=f){
d[v]=d[u]+1;
self(self,v,u);
t[u]=max(t[u],t[v]);
}
};dfs(dfs,n-1,-1);
int ans=-1;
for(int i=0;i<n;++i)if(e[i].size()==1||d[i]%2==1)ans=max(ans,i);
vector<int>k;for(int v:e[n-1])if(t[v]!=-1)k.push_back(t[v]);
sort(k.begin(),k.end());
if(k.size()>=3)ans=max(ans,k.end()[-3]);
for(int i=0;i<n-1;++i){
if(d[i]%2==0){
k.clear();
for(int v:e[i])if(t[v]!=-1)k.push_back(t[v]);
sort(k.begin(),k.end());
if(k.size()>=2)ans=max(ans,k.end()[-2]);
}
}
cout<<ans+1;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3484kb
input:
4 1 2 1 3 1 4
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
5 1 5 5 3 3 4 4 2
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 17ms
memory: 9892kb
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:
99925
result:
ok single line: '99925'
Test #4:
score: -100
Wrong Answer
time: 18ms
memory: 10444kb
input:
99997 90325 59106 22545 8765 88871 37709 14739 95233 8778 29659 48110 57549 91258 76066 15724 65144 48244 87291 12076 94378 41946 96707 93645 12812 53817 34343 72097 94062 81212 263 78713 78150 6754 94906 20957 97539 59293 5018 77961 78090 57262 95225 79349 47902 99024 7869 10613 13728 61757 41090 4...
output:
99996
result:
wrong answer 1st lines differ - expected: '85398', found: '99996'