제출 #98002

#제출 시각아이디문제언어결과실행 시간메모리
98002popovicirobertOne-Way Streets (CEOI17_oneway)C++14
100 / 100
207 ms22848 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long #define ld long double // 217 // 44 using namespace std; const int MAXN = (int) 1e5; vector < pair <int, int> > g[MAXN + 1]; int lvl[MAXN + 1], low[MAXN + 1]; int id[MAXN + 1], cnt; stack <int> stk; char sol[MAXN + 1]; void dfs(int nod, int par) { lvl[nod] = lvl[par] + 1; low[nod] = lvl[nod]; stk.push(nod); bool ok = 0; for(auto it : g[nod]) { if(lvl[it.first] == 0) { dfs(it.first, nod); low[nod] = min(low[nod], low[it.first]); if(low[it.first] > lvl[nod]) { cnt++; while(stk.size() && stk.top() != it.first) { id[stk.top()] = cnt; stk.pop(); } id[stk.top()] = cnt; stk.pop(); sol[it.second] = 0; } } else { if(it.first != par) { low[nod] = min(low[nod], lvl[it.first]); } else { if(ok == 1) { low[nod] = min(low[nod], lvl[it.first]); } ok = 1; } } } } vector < pair <int, int> > tree[MAXN + 1]; pair <int, int> edges[MAXN + 1]; bool vis[MAXN + 1]; int sp[MAXN + 1]; void dfs1(int nod, int par) { vis[nod] = 1; for(auto it : tree[nod]) { if(vis[it.first] == 0) { dfs1(it.first, nod); sp[nod] += sp[it.first]; if(sp[it.first] > 0) { if(id[edges[it.second].first] == it.first) { sol[it.second] = 'R'; } else { sol[it.second] = 'L'; } } else if(sp[it.first] < 0) { if(id[edges[it.second].first] == it.first) { sol[it.second] = 'L'; } else { sol[it.second] = 'R'; } } else { sol[it.second] = 'B'; } } } } int main() { //ifstream cin("A.in"); //ofstream cout("A.out"); int i, n, m, q; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> m; for(i = 1; i <= m; i++) { int x, y; cin >> x >> y; edges[i] = {x, y}; g[x].push_back({y, i}); g[y].push_back({x, i}); } memset(sol, 'B', sizeof(sol)); for(i = 1; i <= n; i++) { if(lvl[i] == 0) { dfs(i, 0); } } cnt++; while(stk.size()) { id[stk.top()] = cnt; stk.pop(); } for(i = 1; i <= n; i++) { for(auto it : g[i]) { if(id[i] != id[it.first]) { tree[id[i]].push_back({id[it.first], it.second}); } } } cin >> q; for(i = 1; i <= q; i++) { int x, y; cin >> x >> y; sp[id[x]]++; sp[id[y]]--; } for(i = 1; i <= cnt; i++) { if(vis[i] == 0) { dfs1(i, 0); } } for(i = 1; i <= m; i++) { cout << sol[i]; } //cin.close(); //cout.close(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...