QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84463 | #5651. Parmigiana With Seafood | Appleblue17 | WA | 43ms | 12048kb | C++14 | 835b | 2023-03-06 15:14:55 | 2023-03-06 15:15:22 |
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];
}
if(u==21){
cout<<"";
}
emx[u]=max(mx,emx[u]);
if(dep[u]%2==0) ans=max(ans,mx2);
}
int main(){
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
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: 3ms
memory: 6644kb
input:
4 1 2 1 3 1 4
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 3ms
memory: 5712kb
input:
5 1 5 5 3 3 4 4 2
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 32ms
memory: 10512kb
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: 0
Accepted
time: 33ms
memory: 12048kb
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:
85398
result:
ok single line: '85398'
Test #5:
score: 0
Accepted
time: 35ms
memory: 10316kb
input:
97687 5206 6282 79497 65247 26426 93558 88096 86680 12934 32573 14514 39078 1619 40141 52678 92737 31478 91858 85427 62603 83477 53003 38500 72325 62910 10306 97005 13325 38472 67023 39728 18368 78232 5993 20560 1752 22173 38357 97114 10935 4680 13734 45188 13484 58025 44787 70778 20 11932 28511 416...
output:
96849
result:
ok single line: '96849'
Test #6:
score: 0
Accepted
time: 20ms
memory: 9984kb
input:
84671 62167 4590 83269 18308 7577 37508 52720 9931 12966 65554 23617 73916 76954 20353 72074 331 3246 58164 41679 28021 41713 36414 53221 77575 53398 66400 21562 16390 11317 20458 70409 48081 43608 84144 4665 70292 65863 62926 53700 32839 82581 18581 56748 30899 75093 58023 10481 13121 60945 8777 26...
output:
84200
result:
ok single line: '84200'
Test #7:
score: 0
Accepted
time: 19ms
memory: 9268kb
input:
73167 47092 28182 66083 3885 43535 13437 54796 24969 69017 27959 4701 13449 69154 70617 71864 8320 65436 18607 63511 58647 49371 16640 57598 9646 69711 6405 44171 46975 10159 72030 72806 67302 70130 62361 61032 23019 22551 71530 15388 46131 2466 41213 7614 7234 7187 68699 69979 18867 73006 9719 7307...
output:
72317
result:
ok single line: '72317'
Test #8:
score: 0
Accepted
time: 32ms
memory: 9724kb
input:
93127 82031 39720 66956 8709 23978 63403 6145 91337 85068 90000 5292 12192 75403 59013 61717 17385 31485 21675 59006 14085 89359 30804 37788 78960 3732 89293 22416 42721 82075 58210 66360 6744 52855 52426 54146 17777 36605 38752 39355 66859 9092 76915 53782 42274 3786 12113 56898 61989 41242 22010 8...
output:
91965
result:
ok single line: '91965'
Test #9:
score: 0
Accepted
time: 27ms
memory: 9540kb
input:
86317 86251 61689 82938 40996 86188 54210 45740 2544 77938 54345 86029 74462 20990 10621 47220 64502 25410 52112 28478 79354 65823 29158 65047 50464 77800 67525 63557 20923 819 43262 68885 63609 39859 33970 33434 26781 35723 54011 85477 27761 64717 2822 33013 20762 22073 14737 67127 32412 14005 3609...
output:
84672
result:
ok single line: '84672'
Test #10:
score: 0
Accepted
time: 20ms
memory: 9388kb
input:
74629 8981 58746 51934 71958 42 26665 13900 16642 57253 62024 22275 58881 12554 22042 61621 36223 32622 35482 14516 3563 45558 3566 28335 31184 28248 10881 45042 46848 59481 4622 50919 21331 28687 6561 34021 51558 71196 18928 31797 14009 74085 4248 25090 1379 62704 62972 74594 49508 17713 1594 39171...
output:
72873
result:
ok single line: '72873'
Test #11:
score: 0
Accepted
time: 29ms
memory: 9828kb
input:
96347 70983 70118 35876 62696 59956 62763 27376 77120 66808 47665 39671 56799 6860 47977 40369 46341 61183 40118 29514 95936 60415 74331 3282 87508 5076 517 1587 1472 92469 70513 13064 90639 35694 77684 9991 64568 51144 75207 80446 4901 39289 76282 95044 27742 30796 71955 43159 31242 37228 54527 453...
output:
93303
result:
ok single line: '93303'
Test #12:
score: 0
Accepted
time: 34ms
memory: 9652kb
input:
86315 23636 66376 78321 16476 59862 46509 35991 14497 68245 40007 25790 45975 37852 32748 56994 48908 81313 36605 3612 55724 43578 62393 48271 80771 31107 85554 71483 22883 60614 73294 41342 41801 17755 41818 16279 57284 77832 75097 15380 26582 68024 23118 67365 36785 35465 20314 22013 73293 26710 7...
output:
84885
result:
ok single line: '84885'
Test #13:
score: 0
Accepted
time: 22ms
memory: 9056kb
input:
76483 57191 19964 14611 24128 25765 7767 76283 48878 36658 43451 41049 8603 68423 1270 15797 45182 53254 15427 52395 45391 66393 11910 72490 44472 25331 44526 20296 54363 37458 73782 23820 30214 17192 57858 10260 1396 14704 3869 74433 30769 52255 65492 28516 12405 68838 65057 17033 33652 48323 57658...
output:
74362
result:
ok single line: '74362'
Test #14:
score: 0
Accepted
time: 34ms
memory: 10120kb
input:
96457 66415 25458 68078 16946 35330 29485 49899 33975 76008 76800 24989 51232 70892 65062 44164 3515 28101 58669 34773 43789 72826 90397 24596 44064 4565 75203 85204 73903 62960 1927 8859 16252 65483 85608 33500 34085 42732 80213 62736 93780 2693 29938 21343 56564 6325 11543 91086 13097 6758 50608 4...
output:
94207
result:
ok single line: '94207'
Test #15:
score: 0
Accepted
time: 43ms
memory: 9748kb
input:
86317 31642 30091 24803 61615 84744 40779 63344 16094 7516 59801 59074 59722 82518 45343 9365 75630 55874 45064 48583 21682 35891 63615 37762 57886 10164 66056 31686 83350 74145 66390 64564 18847 64257 11636 55777 62474 27478 38720 47770 71914 6090 32749 56009 25492 54088 25302 65078 53816 14331 730...
output:
83681
result:
ok single line: '83681'
Test #16:
score: -100
Wrong Answer
time: 30ms
memory: 9436kb
input:
76131 45293 8648 42498 3644 64424 6336 39972 62488 74491 1992 29911 55761 58294 66772 39736 55781 11756 60696 68986 27810 53268 9992 31784 68630 69790 15464 53864 72072 30165 13294 41257 62659 27342 16293 57222 28415 28053 7899 5233 40127 65350 39789 67195 66268 69673 23704 70139 7624 13045 12969 32...
output:
75999
result:
wrong answer 1st lines differ - expected: '73807', found: '75999'