QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#781346#9743. 重心树ZpairWA 26ms15172kbC++20720b2024-11-25 15:48:402024-11-25 15:48:41

Judging History

This is the latest submission verdict.

  • [2024-11-25 15:48:41]
  • Judged
  • Verdict: WA
  • Time: 26ms
  • Memory: 15172kb
  • [2024-11-25 15:48:40]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n;
vector<int> e[N];
vector<pair<int, int> > ans;
set<int> s[N];
void dfs(int p,int fa){
	s[p].insert(p);
	for(int t:e[p]){
		if(t==fa)continue;
		dfs(t,p);
		for(int x:s[t])s[p].insert(x);
		ans.push_back({p,*(--s[t].lower_bound(p))});
	}
}
void solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		e[i].clear(),s[i].clear();
	for(int i=1;i<=n;++i){
		int x,y;
		scanf("%d",&x);
		while(x--){
			scanf("%d",&y);
			e[i].push_back(y);
			e[y].push_back(i);
		}
	}
	dfs(1,0);
	for(auto [x,y]:ans)
		printf("%d %d\n",x,y);
	ans.clear();
}
int main(){
	int T;cin>>T;
	while(T--)solve();
}
/*
1
4
2 3 4
1 3
0
0
*/

详细

Test #1:

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

input:

2
4
2 3 4
1 3
0
0
3
1 3
1 3
0

output:

3 2
1 2
1 4
3 2
1 2

result:

ok Accepted (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 26ms
memory: 15172kb

input:

40000
3
2 2 3
0
0
2
1 2
0
4
2 4 3
1 4
0
0
5
1 3
2 5 4
1 5
0
0
4
3 2 3 4
0
0
0
2
1 2
0
2
1 2
0
5
1 2
3 3 4 5
0
0
0
2
1 2
0
2
1 2
0
5
4 2 3 4 5
0
0
0
0
4
1 2
2 3 4
0
0
5
2 5 4
1 5
1 4
0
0
2
1 2
0
5
1 2
3 3 4 5
0
0
0
5
2 2 3
0
2 4 5
0
0
5
2 5 4
1 5
1 4
0
0
5
2 2 4
2 3 5
0
0
0
4
1 3
1 4
1 4
0
4
2 4 3
1 ...

output:

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

result:

wrong answer The index of the node i's father should less than i (test case 4)