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 int long long
using namespace std;
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);		
	int N, Q;
	char T;
	int a , b;
	cin >> N >> Q;
	vector<vector<vector<int>>> adj(N+1, vector<vector<int>>(2)); 
	pair <int, int> temp;
	vector<int> visited(N+1, -1);
	queue<pair<int, int>> q;
	for (int i = 0; i < Q; ++i){
		cin >> T >> a >> b;
		if (T == 'R'){adj[a][0].push_back(b);adj[b][0].push_back(a);}
		else if (T == 'A'){adj[a][1].push_back(b);adj[b][1].push_back(a);}
		else{
			visited = vector<int>(N+1, -1);
			q = queue<pair<int, int>>();
			q.push({a, 0});
			visited[a] = 0;
			while (!q.empty() && visited[b] == -1){
				temp = q.front();
				q.pop();
				
				for (int i = 0; i < adj[temp.first][0].size(); ++i){
					if (visited[temp.first] != -1){
						q.push({adj[temp.first][0][i], temp.second});
						visited[adj[temp.first][0][i]] = temp.second;
					}
				}
				for (int i = 0; i < adj[temp.first][1].size(); ++i){
					if (visited[temp.first] != -1){
						q.push({adj[temp.first][1][i], temp.second ^ 1});
						visited[adj[temp.first][1][i]] = temp.second ^ 1;
					}
				}
				}
			if (visited[b] == -1)cout << "?\n";
			else if (visited[b] == 0)cout << "R\n";
			else cout << "A\n";
		}
	}
}
Compilation message (stderr)
charges.cpp: In function 'int main()':
charges.cpp:28:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i = 0; i < adj[temp.first][0].size(); ++i){
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
charges.cpp:34:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int i = 0; i < adj[temp.first][1].size(); ++i){
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |