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>
using namespace std;
const int MAX_N = 1e5 + 5;
const int MAX_M = 1e5 + 5;
vector <int> graph[MAX_N];
int L[MAX_M], R[MAX_M];
bool visited[MAX_N];
int qs1[MAX_N], qs2[MAX_N];
char ans[MAX_M];
void dfs(int u, int p) {
visited[u] = true;
for(auto i : graph[u]) {
int v = u ^ L[i] ^ R[i];
if(v == p) {
continue;
}
if(visited[v] == false) {
dfs(v, u);
}
else {
ans[i] = 'B';
qs1[u]++;
qs1[v]--;
}
}
}
void dfs2(int u) {
visited[u] = false;
for(auto i : graph[u]) {
int v = u ^ L[i] ^ R[i];
if(visited[v] == true) {
dfs2(v);
ans[i] = 'B';
qs1[u] += qs1[v];
qs2[u] += qs2[v];
if(qs1[v] > 0 or qs2[v] == 0) {
continue;
}
if(qs2[v] > 0) {
if(v == L[i]) {
ans[i] = 'R';
}
else {
ans[i] = 'L';
}
}
else {
if(v == L[i]) {
ans[i] = 'L';
}
else {
ans[i] = 'R';
}
}
}
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i++) {
cin >> L[i] >> R[i];
graph[L[i]].push_back(i);
graph[R[i]].push_back(i);
}
for(int i = 1; i <= n; i++) {
if(visited[i] == false) {
dfs(i, -1);
}
}
int p;
cin >> p;
for(int i = 1; i <= p; i++) {
int x, y;
cin >> x >> y;
qs2[x]++;
qs2[y]--;
}
for(int i = 1; i <= n; i++) {
if(visited[i] == true) {
dfs2(i);
}
}
for(int i = 1; i <= m; i++) {
cout << ans[i];
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |