#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];
int X[MAX_N], Y[MAX_N];
bool visited[MAX_N];
bool is_cycle[MAX_M];
int qs[MAX_N];
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 {
is_cycle[i] = true;
// qs[u]++;
// qs[v]--;
}
}
}
void dfs2(int u) {
visited[u] = true;
for(auto i : graph[u]) {
int v = u ^ L[i] ^ R[i];
if(visited[v] == false) {
dfs2(v);
qs[u] += qs[v];
}
}
}
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++) {
cin >> X[i] >> Y[i];
qs[X[i]]++;
qs[Y[i]]--;
}
fill(visited + 1, visited + n + 1, false);
for(int i = 1; i <= n; i++) {
if(visited[i] == false) {
dfs2(i);
}
}
for(int i = 1; i <= m; i++) {
if(is_cycle[i] == true) {
cout << 'B';
continue;
}
if(qs[L[i]] < 0 or qs[R[i]] > 0) {
cout << 'L';
}
else if(qs[L[i]] > 0 or qs[R[i]] < 0) {
cout << 'R';
}
else {
cout << 'B';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |