Submission #1090762

#TimeUsernameProblemLanguageResultExecution timeMemory
1090762Onur_IlgazPalindromi (COCI22_palindromi)C++17
0 / 110
13 ms3416 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...