QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#751895#9743. 重心树doyoWA 0ms5764kbC++20716b2024-11-15 21:12:562024-11-15 21:12:56

Judging History

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

  • [2024-11-15 21:12:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5764kb
  • [2024-11-15 21:12:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,j,k) for(int i=j;i<=k;++i)
#define For(i,j,k) for(int i=j;i>=k;--i)
const int N = 2e5 + 111;
int p[N];
int bcj[N];
vector<int> e[N];
int fd(int x){return bcj[x]==x?x:bcj[x]=fd(bcj[x]);} 
void sol(){
	int n;
	cin>>n;
	FOR(i,1,n){
		e[i].clear();
		int num,tmp;
		cin>>num;
		FOR(j,1,num){
			cin>>tmp;
			e[i].push_back(tmp);
		}
	}
	FOR(i,1,n) bcj[i] = i;
	For(i,n,1){
		for(auto nxt:e[i]){
			bcj[fd(nxt)] = i;
		}
	}
	FOR(i,2,n){
		cout<<i<<' '<<fd(i)<<'\n';
	} 
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		sol();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 5764kb

input:

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

output:

2 1
3 1
4 1
2 1
3 1

result:

wrong answer The center of node 1 is incorrect (test case 1)