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;
typedef long long ll;
typedef long double ld;
const int INF = (int) 1e9 + 1e6 + 123;
const ll LINF = (ll) 1e18 + 1e9 + 123;
#define rep(i, s, t) for (auto i = (s); i < (t); ++(i))
#define per(i, s, t) for (auto i = (s); i >= (t); --(i))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
bool mini(auto &x, const auto &y) {
if (y < x) {
x = y;
return 1;
}
return 0;
}
bool maxi(auto &x, const auto &y) {
if (y > x) {
x = y;
return 1;
}
return 0;
}
void run();
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
run();
return 0;
}
const int N = (int) 22;
struct E {
int a, b;
};
int n, m;
E e[N];
vector<pair<int, int>> g[N];
bool can[N][N];
bool can_left[N], can_right[N];
int p;
int x[N], y[N];
void floyd() {
rep(k, 1, n + 1) rep(i, 1, n + 1) rep(j, 1, n + 1) can[i][j] |= can[i][k] && can[k][j];
}
bool test(int mask, int bit) {
return mask & (1 << bit);
}
void run() {
cin >> n >> m;
rep(i, 0, m) {
cin >> e[i].a >> e[i].b;
g[e[i].a].pb({e[i].b, i});
g[e[i].b].pb({e[i].a, i});
}
cin >> p;
rep(i, 0, p) {
cin >> x[i] >> y[i];
}
rep(mask, 0, 1 << m) {
memset(can, 0, sizeof can);
rep(i, 0, m) {
int u = e[i].a;
int v = e[i].b;
if (test(mask, i)) {
swap(u, v);
}
can[u][v] |= 1;
}
floyd();
bool ok = 1;
rep(i, 0, p) {
ok &= can[x[i]][y[i]];
}
if (!ok) continue;
rep(i, 0, m) {
if (test(mask, i)) {
can_left[i] = 1;
} else {
can_right[i] = 1;
}
}
}
rep(i, 0, m) {
if (can_left[i] && can_right[i]) {
cout << 'B';
} else if (can_left[i]) {
cout << 'L';
} else if (can_right[i]) {
cout << 'R';
} else {
assert(false);
}
}
cout << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |