이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)
const int MOD = 1e9 + 7;
const int MX = 1e5 + 10;
const ll INF = 1e18;
int N, M, P; vi adj[MX]; vpi edges;
int timer = 1; bool vis1[MX]; int in[MX], low[MX]; map<pi, bool> bridges;
int nComp = 1; int comp[MX]; vi compAdj[MX]; int val[MX], depth[MX]; bool vis2[MX];
void DFS1(int X) {
vis1[X] = true; in[X] = low[X] = timer++;
EACH(Y, adj[X]) {
if (vis1[Y]) { low[X] = min(low[X], in[Y]); continue; } // Back Edge
adj[Y].erase(find(all(adj[Y]), X)); DFS1(Y); low[X] = min(low[X], low[Y]);
if (low[Y] > in[X]) bridges[{X, Y}] = bridges[{Y, X}] = true;
}
}
void genComp(int X, int label) {
comp[X] = label; EACH(Y, adj[X]) if (!comp[Y] && !bridges[{X, Y}]) genComp(Y, label);
}
void DFS2(int X, int P) {
vis2[X] = true; EACH(Y, compAdj[X]) if (Y != P) { depth[Y] = depth[X] + 1; DFS2(Y, X); val[X] += val[Y]; }
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> N >> M; F0R(i, M) { int A, B; cin >> A >> B; adj[A].pb(B), adj[B].pb(A); edges.pb({A, B}); }
FOR(i, 1, N + 1) if (!vis1[i]) DFS1(i); FOR(i, 1, N + 1) if (!comp[i]) genComp(i, nComp++);
EACH(P, edges) if (bridges[{P.f, P.s}]) {
int A = comp[P.f], B = comp[P.s]; compAdj[A].pb(B), compAdj[B].pb(A);
}
cin >> P; F0R(i, P) {
int A, B; cin >> A >> B; val[comp[A]]++, val[comp[B]]--;
}
FOR(i, 1, nComp) if (!vis2[i]) DFS2(i, 0);
F0R(i, M) { pi E = edges[i];
if (!bridges[{E.f, E.s}]) { cout << "B"; continue; }
int A = comp[E.f], B = comp[E.s]; int LOW = depth[A] > depth[B] ? A : B;
if (val[LOW] == 0) { cout << "B"; continue; }
int cnt = 0; if (depth[A] > depth[B]) cnt++; if (val[LOW] > 0) cnt++;
if (cnt % 2) 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... |