QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84904#5651. Parmigiana With SeafoodxxzxWA 2ms6756kbC++14868b2023-03-06 20:55:422023-03-06 20:56:19

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 20:56:19]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 6756kb
  • [2023-03-06 20:55:42]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,dep[N],ans,f[N][2];
vector<int> g[N];
bool cmp(int x,int y) { return x>y; }
void dfs(int x,int from) {
    dep[x]=dep[from]+1;
    if(g[x].size()<=1||(x!=n&&dep[x]%2)) ans=max(ans,x);
    f[x][dep[x]&1]=x;
    vector<int> s;
    for(auto y:g[x]) if(y!=from){
        dfs(y,x);
        f[x][0]=max(f[x][0],f[y][0]), f[x][1]=max(f[x][1],f[y][1]);
        s.emplace_back(f[y][dep[x]&1]);
    }
    sort(s.begin(),s.end(),cmp);
    if(dep[x]%2&&s.size()>=2&&x!=n) ans=max(ans,s[1]);
    if(s.size()>=3) ans=max(ans,s[2]);
}
int main() {
    scanf("%d",&n);
    for(int i=1,u,v;i<n;i++) {
        scanf("%d%d",&u,&v);
        g[u].emplace_back(v), g[v].emplace_back(u);
    }
    if(n%2==0) return printf("%d\n",n), 0;
    dfs(n,0);
    printf("%d\n",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6756kb

input:

4
1 2
1 3
1 4

output:

4

result:

ok single line: '4'

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 5900kb

input:

5
1 5
5 3
3 4
4 2

output:

4

result:

wrong answer 1st lines differ - expected: '3', found: '4'