QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#791600#9743. 重心树bluejellyfishWA 0ms3816kbC++23700b2024-11-28 19:48:462024-11-28 19:48:51

Judging History

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

  • [2024-11-28 19:48:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3816kb
  • [2024-11-28 19:48:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
//#define x first
//#define y second
const int mod = 1e9 + 7;
int f[300000];
int find(int x) {
	if(x != f[x]) x = f[x] = f[f[x]];
	return f[x];
}
void miss() {
	int n;
	cin >> n;
	vector<vector<int>>mp(n + 1);
	for(int i = 1; i <= n; i++) {
		f[i] = i;
		int x;
		for(cin >> x; x; x--) {
			int it;
			cin >> it;
			mp[i].push_back(it);
		}
	}
	for(int i = n; i; i--) {
		for(auto x : mp[i]) {
			cout << i << " " << find(x);
			f[find(x)] = i;
		}
	}
}
signed main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int T = 1;
    cin >> T;
	while(T--) miss();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

2 31 21 42 31 2

result:

wrong answer Tree can't contain loops (test case 1)