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;
#define int long long
vector < int > adj[1002];
pair < int, int > road[1002];
pair < int, int > haveTo[1002];
int subOf[1002];
bool visited[1002];
bool poss = false;
void dfs(int x, int s, int e) {
visited[x] = true;
if (x == e) {
poss = true;
return;
}
subOf[x] = 1;
for (auto u: adj[x]) {
if (!visited[u] && (x != s || u != e)) {
dfs(u, s, e);
}
if (poss) return;
}
}
int32_t main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int s, e;
cin >> s >> e;
adj[s].push_back(e);
adj[e].push_back(s);
road[i] = {
s,
e
};
}
int p;
cin >> p;
for (int i = 1; i <= p; i++) {
int s, e;
cin >> s >> e;
haveTo[i] = {
s,
e
};
}
for (int i = 1; i <= m; i++) {
int s = road[i].first, e = road[i].second;
bool toL = true, toR = true;
fill(visited, visited + 1002, false);
fill(subOf, subOf + 1002, 0);
poss = false;
int cnt = 0;
for (auto u: adj[s]) {
if (u == e) cnt++;
}
if (cnt > 1) {
cout << "B";
continue;
}
dfs(s, s, e);
if (poss) {
cout << "B";
} else {
for (int j = 1; j <= p; j++) {
if (subOf[haveTo[j].first] == 1 && subOf[haveTo[j].second] == 0) {
toL = false;
}
if (subOf[haveTo[j].first] == 0 && subOf[haveTo[j].second] == 1) {
toR = false;
}
}
if (toL && toR) cout << "B";
else if (toL) cout << "L";
else cout << "R";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |