/** This is the end ... **/
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define int long long int
#define dint long double
#define endl "\n"
#define pii pair<int, int>
#define pb push_back
#define F first
#define S second
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 23;
const int MAXK = (int)40000 + 23;
const int MAX_LOG = 23;
const int PRM = (int)31622 + 23;
const int INF = (int)9e9;
int POW(int x, int y) {
return (!y ? 1 : (y & 1 ? x * POW(x * x % MOD, y / 2) % MOD : POW(x * x % MOD, y / 2) % MOD));
}
int n, m, s, q, t, tmp, tmp2, cmp, u, v, u2, v2, ans1, ans2, k, flag, l, r, mid;
int arr[MAXN], cnt[MAXN], h[MAXN], seen[MAXN], pow2dad[MAXN][MAX_LOG], cnt2[MAXN], dad[MAXN], bala[MAXN], payin[MAXN], bkedge[MAXN];
vector<pii> adj[MAXN];
vector<pii> edge;
vector<int> vec, e[MAXN];
int num[MAXN], low[MAXN], ti, comp[MAXN], w[MAXN];
void dfs(int u, int p) {
vec.pb(u);
ti++;
low[u] = ti;
num[u] = ti;
for (auto cur:adj[u]) {
v = cur.F;
if (cur.S == p || comp[v]) continue;
if (!num[v]) {
dfs(v, cur.S);
low[u] = min(low[u], low[v]);
} else {
low[u] = min(low[u], num[v]);
}
}
if (low[u] == num[u]) {
m++;
while (vec.size()) {
v = vec.back();
vec.pop_back();
comp[v] = m;
for (auto w:adj[v]) {
if (comp[w.first] && m != comp[w.first]) {
e[m].push_back(comp[w.first]);
}
}
if (v == u) break;
}
}
}
void pull(int u) {
num[u] = 1;
for (auto v: e[u]) {
if (!num[v]) pull(v);
w[u] += w[v];
}
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i=1; i<=m; i++) {
cin >> u >> v;
edge.pb({u, v});
adj[u].pb({v, i});
adj[v].pb({u, i});
}
for (int i = 1; i <= n; ++i) {
if (num[i]) continue;
dfs(i, 0);
}
cin >> q;
while (q--) {
int u, v;
cin >> u >> v;
u = comp[u], v = comp[v];
if (u == v) continue;
++w[u], --w[v];
}
memset(num, 0, sizeof(num));
for (int i = 1; i <= m; ++i) {
if (num[i]) continue;
pull(i);
}
for (int i = 0; i < edge.size(); ++i) {
int u = edge[i].first;
int v = edge[i].second;
u = comp[u], v = comp[v];
if (u == v) {
cout << 'B';
continue;
}
if (u > v) {
if (w[v] < 0) cout << 'R';
if (w[v] > 0) cout << 'L';
if (w[v] == 0) cout << 'B';
} else {
if (w[u] < 0) cout << 'L';
if (w[u] > 0) cout << 'R';
if (w[u] == 0) cout << 'B';
}
}
return 0;
}
Compilation message
oneway.cpp: In function 'int32_t main()':
oneway.cpp:116:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
116 | for (int i = 0; i < edge.size(); ++i) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
11220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
11220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
11220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |