QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#791600 | #9743. 重心树 | bluejellyfish | WA | 0ms | 3816kb | C++23 | 700b | 2024-11-28 19:48:46 | 2024-11-28 19:48:51 |
Judging History
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)