QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#406639#5651. Parmigiana With SeafoodJryno1WA 51ms24192kbC++141.5kb2024-05-07 15:39:382024-05-07 15:39:38

Judging History

你现在查看的是最新测评结果

  • [2024-05-07 15:39:38]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:24192kb
  • [2024-05-07 15:39:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
int n,deg[maxn];
vector<int>ed[maxn];
int ans=0;
void dfs(int x,int fat,int dis){
    if(dis&1)ans=max(ans,x);
    for(auto v:ed[x]){
        if(v==fat)continue;
        dfs(v,x,dis+1);
    }
}
int mval[maxn],mdep;
int sval[maxn][2];
void c1(int x,int fat,int d){
    mdep=max(mdep,d);
    if(d%4==0){
        if(x>mval[d])ans=max(ans,mval[d]),mval[d]=x;
        else ans=max(ans,x);
    }
    mval[d]=max(mval[d],x);
    for(auto v:ed[x]){
        if(v==fat)continue;
        c1(v,x,d+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);
        for(auto v:ed[n]){
            mdep=0,c1(v,n,1);
            // for(int i=2;i<=mdep;i+=2){
            //     if(mval[i]>sval[i][0]){
            //         ans=max(ans,sval[i][1]);
            //         sval[i][1]=sval[i][0];
            //         sval[i][0]=mval[i];
            //     } else if(mval[i]>sval[i][1]){
            //         ans=max(ans,sval[i][1]);
            //         sval[i][1]=mval[i];
            //     } else if(sval[i][1]) ans=max(ans,mval[i]);
            // }
            // for(int i=1;i<=mdep;i++)mval[i]=0;
        }
        cout<<ans<<"\n";
    } else cout<<n<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 17940kb

input:

4
1 2
1 3
1 4

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 19992kb

input:

5
1 5
5 3
3 4
4 2

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 40ms
memory: 21392kb

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: 51ms
memory: 24192kb

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:

99803

result:

wrong answer 1st lines differ - expected: '85398', found: '99803'