QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#791600#9743. 重心树bluejellyfishWA 0ms3816kbC++23700b2024-11-28 19:48:462024-11-28 19:48:51

Judging History

This is the latest submission verdict.

  • [2024-11-28 19:48:51]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3816kb
  • [2024-11-28 19:48:46]
  • Submitted

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();
}

详细

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)