QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#154543#6307. Chase Game 2qzez#WA 5ms6308kbC++141.1kb2023-08-31 18:53:392023-08-31 18:53:41

Judging History

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

  • [2023-08-31 18:53:41]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:6308kb
  • [2023-08-31 18:53:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
	if(x.empty())return out<<"[]";
	out<<'['<<x[0];
	for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
	return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
	cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
	cerr<<x<<' ',debug(y...);
}
const int N=1e5+10;
int T,n,deg[N];
vector<int>to[N];
void get(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++){
		scanf("%d%d",&u,&v),deg[u]++,deg[v]++;
		to[u].push_back(v),to[v].push_back(u);
	}
	if(*max_element(deg+1,deg+1+n)==n-1){
		puts("-1");return;
	}
	int cnt=0;
	for(int i=1;i<=n;i++)cnt+=deg[i]==1;
	int tot=0;
	for(int v:to[1])tot+=deg[v]==1;
	cnt-=tot;
	printf("%d\n",tot+(cnt+1)/2);
}
void clr(){
	fill(deg,deg+1+n,0);
	for(int i=1;i<=n;i++)to[i].clear();
}
int main(){
	for(scanf("%d",&T);T--;clr())get();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 6200kb

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: 5ms
memory: 6308kb

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:

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

result:

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