This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
const int N = 100001;
int par[N], w[N];
int parent(int x) {
if(par[x] == x) return x;
return par[x] = parent(par[x]);
}
void merge(int a, int b) {
a = parent(a);
b = parent(b);
if(w[a] < w[b]) swap(a, b);
par[b] = a;
w[a] += w[b];
}
int32_t main(){
fast
int n;
cin >> n;
string s;
cin >> s;
s = " " + s;
for(int i = 1; i <= n; i++) {
par[i] = i;
w[i] = 1;
}
for(int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
merge(a, b);
cout << w[parent(a)] << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |