QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#253540#6307. Chase Game 2SATSKYWA 2ms3784kbC++20843b2023-11-17 07:39:062023-11-17 07:39:06

Judging History

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

  • [2023-11-17 07:39:06]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3784kb
  • [2023-11-17 07:39:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;using ll=long long;const ll inf=1e17;
struct S
{
	vector<int>ec;int rot,cnt=0,mx=0;
	vector<vector<int>>es;
	int spr(int x,int lst)
	{
		int cc=0;for(auto k:es[x])if(k!=lst)cc+=spr(k,x);
		mx=max(mx,cc);if(!cc){cnt++;return 1;}return 0;
	}
	void solve()
	{
		int n;cin>>n;es.resize(n+1),ec.resize(n+1,0);
		for(int i=1,u,v;i<n;i++)cin>>u>>v,es[u].push_back(v),es[v].push_back(u),ec[u]++,ec[v]++;
		for(int i=1,mx=-1;i<=n;i++)if(ec[i]>mx)mx=ec[i],rot=i;if(ec[rot]==n-1) { cout<<"-1\n";return; }
		spr(rot,0);cout<<max(mx,(cnt+1)/2)<<'\n';
	}
};
int main()
{
	//freopen("3.in","r",stdin);
	//cout<<fixed<<setprecision(12);
	ios::sync_with_stdio(0);cin.tie(0);
	int t=1;cin>>t;
	//clock_t a=clock();
	while(t--){S SS;SS.solve();}
	//cout<<"Time:"<<double(clock()-a)<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3784kb

input:

4
2
1 2
4
1 2
2 3
3 4
4
1 2
2 3
2 4
5
1 2
2 3
3 4
3 5

output:

-1
1
-1
2

result:

ok 4 number(s): "-1 1 -1 2"

Test #2:

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

input:

10000
4
1 2
1 3
3 4
4
1 2
1 3
1 4
4
1 2
2 3
1 4
5
1 2
2 3
1 4
4 5
5
1 2
2 3
3 4
4 5
4
1 2
2 3
2 4
5
1 2
1 3
2 4
2 5
4
1 2
2 3
1 4
5
1 2
1 3
2 4
1 5
5
1 2
2 3
3 4
2 5
5
1 2
1 3
2 4
2 5
4
1 2
1 3
3 4
5
1 2
1 3
3 4
1 5
4
1 2
1 3
1 4
5
1 2
1 3
3 4
3 5
5
1 2
2 3
3 4
3 5
4
1 2
1 3
2 4
5
1 2
2 3
2 4
3 5
5
...

output:

1
-1
1
2
2
-1
2
1
2
2
2
1
2
-1
2
2
1
2
2
1
1
1
-1
2
2
2
1
-1
1
2
2
2
1
-1
2
2
1
1
1
-1
1
1
2
2
2
2
1
1
-1
1
2
1
2
2
1
2
1
1
2
-1
-1
-1
2
2
2
2
2
1
2
2
2
-1
1
2
-1
2
2
-1
2
-1
-1
2
2
2
2
2
1
2
1
1
1
2
1
1
2
-1
2
1
2
-1
2
1
1
2
-1
2
-1
1
-1
-1
2
-1
2
1
2
2
2
2
1
1
2
2
1
1
2
-1
2
1
2
1
1
2
2
2
1
1
2
-1...

result:

wrong answer 4th numbers differ - expected: '1', found: '2'