QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#406658 | #5651. Parmigiana With Seafood | Jryno1 | WA | 52ms | 26900kb | C++14 | 1.1kb | 2024-05-07 16:10:21 | 2024-05-07 16:10:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
int n,deg[maxn],dep[maxn],cnt[maxn],vis[maxn],fa[maxn];
vector<int>ed[maxn];
int ans=0;
void dfs(int x,int fat,int dis){
fa[x]=fat;
if(dis&1)ans=max(ans,x);
dep[x]=dis;
for(auto v:ed[x]){
if(v==fat)continue;
dfs(v,x,dis+1);
}
}
int main(){
cin>>n;
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
ed[u].push_back(v);
ed[v].push_back(u);
deg[u]++,deg[v]++;
}
if(n&1){
for(int i=1;i<=n;i++)if(deg[i]==1)ans=max(ans,i);
dfs(n,0,0);
vis[n]=1;
for(int i=n;i>=1;i--){
if(dep[i]&1){
cout<<i<<"\n";
return 0;
}
int now=i;
while(!vis[now]){
vis[now]=1;
cnt[now]++,cnt[fa[now]]++,now=fa[now];
}
if(cnt[now]>2&&!(dep[now]&1)){
cout<<i<<"\n";
return 0;
}
}
} else cout<<n<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 17764kb
input:
4 1 2 1 3 1 4
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 23240kb
input:
5 1 5 5 3 3 4 4 2
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 38ms
memory: 26900kb
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: 52ms
memory: 26388kb
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:
85397
result:
wrong answer 1st lines differ - expected: '85398', found: '85397'