이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 2e5+100, M = 1e5+10, K = 20;
int n, m, p, tin[N], tout[N], up[N][K], par[N][2], lo[N], timer = 0, ti[N], dp[N];
vector<pair<int, int>> g[N], f[N];
vector<bool> vis, bridge;
string s = "";
void st(int v){
vis[v] = 1;
for(auto U: g[v]){
int u = U.first, idx = U.second;
if(!vis[u]){
f[v].pb({u, idx});
f[u].pb({v, idx^1});
par[u][0] = v;
par[u][1] = idx;
st(u);
}
}
}
void pre(int v, int p){
tin[v] = timer++;
up[v][0] = p;
for(auto U: f[v]){
int u = U.first;
if(u != p){
pre(u, v);
}
}
tout[v] = timer++;
}
bool is_ancestor(int u, int v){
return tin[u] <= tin[v] && tout[v] <= tout[u];
}
int _lca(int u, int v){
if(is_ancestor(u, v)) return u;
if(is_ancestor(v, u)) return v;
for(int j = K - 1; j >= 0 ;--j){
if(!is_ancestor(up[u][j], v)) u = up[u][j];
}
return up[u][0];
}
void bf(int v, int pp){
ti[v] = lo[v] = timer++;
vis[v] = 1;
for(auto U: g[v]){
int u = U.first, idx = U.second;
if(idx/2 == pp/2) continue;
if(vis[u]){
lo[v] = min(lo[v], ti[u]);
}else{
bf(u, idx);
lo[v] = min(lo[v], lo[u]);
if(lo[u] > ti[v]){
bridge[idx>>1] = 1;
}
}
}
}
int dfs(int v, int p){
int w = 0;
vis[v] = 1;
for(auto U: f[v]){
int u = U.first;
if(u != p){
w += dfs(u, v);
}
}
w += dp[v];
if(p != v){
if(w < 0){
int e = par[v][1];
if(bridge[e>>1]){
s[e>>1] = ((e&1)^1) ? 'R' : 'L';
}
}else if(w > 0){
int e = par[v][1];
if(bridge[e>>1]){
s[e>>1] = (e&1) ? 'R' : 'L';
}
}
}
return w;
}
void solve(){
cin >> n >> m;
for(int i = 0 ; i < m; ++i){
int u, v; cin >> u >> v;
g[u].pb({v, i*2});
g[v].pb({u, i*2+1});
s += 'B';
}
vis.resize(n + 1, 0);
for(int i = 1; i <= n; ++i) if(!vis[i]) st(i), pre(i, i);
for(int j = 1; j < K; ++j) for(int i = 1; i <= n; ++i) up[i][j] = up[up[i][j - 1]][j - 1];
vis.clear();
vis.resize(n + 1, 0);
bridge.resize(m, 0);
timer = 0;
for(int i = 1; i <= n; ++i) if(!vis[i]) bf(i, MOD);
cin >> p;
for(int i = 0; i < p; ++i){
int u, v; cin >> u >> v;
dp[u]++;
dp[v]--;
}
vis.clear();
vis.resize(n, 0);
for(int i = 1; i <= n; ++i) if(!vis[i]) dfs(i, i);
cout << s;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// freopen("in.txt", "r", stdin);
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
oneway.cpp: In function 'int main()':
oneway.cpp:136:14: warning: unused variable 'aa' [-Wunused-variable]
136 | int T = 1, aa;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |