QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#406683#5651. Parmigiana With SeafooddykwWA 21ms10972kbC++20885b2024-05-07 16:38:462024-05-07 16:38:47

Judging History

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

  • [2024-05-07 16:38:47]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:10972kb
  • [2024-05-07 16:38:46]
  • 提交

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),k,s,p(n),q(n),r(n);
auto dfs=[&](auto&self,int u,int f)->void{
	static int z=-1;p[u]=++z,r[z]=u;
	if(u!=n-1&&d[u]%2==0)k.push_back(u);
	if(d[u]==2)s.push_back(u);
	for(int v:e[u])if(v!=f){
		d[v]=d[u]+1;
		self(self,v,u);
	}
	q[u]=z;
};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);
sort(k.begin(),k.end());
if(k.size()>=3)ans=max(ans,k.end()[-3]);
for(int u:s){
	k.clear();
	for(int i=p[u]+1;i<=q[u];++i){
		int v=r[i];
		if(d[v]%2==0)k.push_back(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: 3592kb

input:

4
1 2
1 3
1 4

output:

4

result:

ok single line: '4'

Test #2:

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

input:

5
1 5
5 3
3 4
4 2

output:

3

result:

ok single line: '3'

Test #3:

score: -100
Wrong Answer
time: 21ms
memory: 10972kb

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:

99996

result:

wrong answer 1st lines differ - expected: '99925', found: '99996'