Submission #1090762

# Submission time Handle Problem Language Result Execution time Memory
1090762 2024-09-18T17:28:44 Z Onur_Ilgaz Palindromi (COCI22_palindromi) C++17
0 / 110
13 ms 3416 KB
#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
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -