QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#751885#9743. 重心树doyoWA 16ms5644kbC++20717b2024-11-15 21:11:032024-11-15 21:11:03

Judging History

This is the latest submission verdict.

  • [2024-11-15 21:11:03]
  • Judged
  • Verdict: WA
  • Time: 16ms
  • Memory: 5644kb
  • [2024-11-15 21:11:03]
  • Submitted

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<<' '<<bcj[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: 100
Accepted
time: 1ms
memory: 5624kb

input:

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

output:

2 1
3 2
4 1
2 1
3 2

result:

ok Accepted (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 16ms
memory: 5644kb

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:

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

result:

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