Submission #689902

# Submission time Handle Problem Language Result Execution time Memory
689902 2023-01-29T17:37:18 Z sudheerays123 Experimental Charges (NOI19_charges) C++17
100 / 100
29 ms 3788 KB
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
const ll N = 1e5+5 , INF = 1e18 , MOD = 1e9+7;

vector<ll> par(N),len(N);

void make_set(ll n){
	for(ll i = 1; i <= n; i++){
		par[i] = i;
		len[i] = 0;
	}
}

pair<ll,ll> get(ll x){
	if(x == par[x]) return make_pair(x,0);

	pair<ll,ll> u = get(par[x]);
	par[x] = u.first;
	len[x] = (len[x]+u.second)%2;

	return make_pair(par[x],len[x]);
}

void add_edge(ll a , ll b , ll c){

	pair<ll,ll> x = get(a);
	pair<ll,ll> y = get(b);

	if(x.first == y.first) return;

	par[x.first] = y.first;
	len[x.first] = (x.second+c+y.second)%2;
}

void solve(){

	ll n,q;
	cin >> n >> q;

	make_set(n);

	while(q--){
		char x;
		ll a,b;
		cin >> x >> a >> b;

		if(x == 'R'){
			add_edge(a,b,0);
		}
		else if(x == 'A'){
			add_edge(a,b,1);
		}
		else{
			pair<ll,ll> x = get(a);
			pair<ll,ll> y = get(b);

			if(x.first != y.first) cout << "?\n";
			else{
				if((x.second+y.second)%2 == 0) cout << "R\n";
				else cout << "A\n";
			}
		}
	}

}

int main(){

	fast;

	ll tc = 1;
	// cin >> tc;
	while(tc--) solve();

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 2796 KB Output is correct
2 Correct 19 ms 2800 KB Output is correct
3 Correct 22 ms 2892 KB Output is correct
4 Correct 23 ms 2896 KB Output is correct
5 Correct 20 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3296 KB Output is correct
2 Correct 25 ms 3220 KB Output is correct
3 Correct 21 ms 3176 KB Output is correct
4 Correct 29 ms 3236 KB Output is correct
5 Correct 22 ms 3312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3788 KB Output is correct
2 Correct 28 ms 3448 KB Output is correct
3 Correct 24 ms 3164 KB Output is correct
4 Correct 24 ms 3288 KB Output is correct
5 Correct 25 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 2 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 2 ms 1876 KB Output is correct
9 Correct 1 ms 1908 KB Output is correct
10 Correct 1 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 19 ms 2796 KB Output is correct
7 Correct 19 ms 2800 KB Output is correct
8 Correct 22 ms 2892 KB Output is correct
9 Correct 23 ms 2896 KB Output is correct
10 Correct 20 ms 2772 KB Output is correct
11 Correct 24 ms 3296 KB Output is correct
12 Correct 25 ms 3220 KB Output is correct
13 Correct 21 ms 3176 KB Output is correct
14 Correct 29 ms 3236 KB Output is correct
15 Correct 22 ms 3312 KB Output is correct
16 Correct 20 ms 3788 KB Output is correct
17 Correct 28 ms 3448 KB Output is correct
18 Correct 24 ms 3164 KB Output is correct
19 Correct 24 ms 3288 KB Output is correct
20 Correct 25 ms 3156 KB Output is correct
21 Correct 2 ms 1876 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 2 ms 1876 KB Output is correct
24 Correct 1 ms 1908 KB Output is correct
25 Correct 1 ms 1912 KB Output is correct
26 Correct 27 ms 3176 KB Output is correct
27 Correct 24 ms 3176 KB Output is correct
28 Correct 23 ms 3148 KB Output is correct
29 Correct 22 ms 3060 KB Output is correct
30 Correct 23 ms 3192 KB Output is correct