Submission #1093030

#TimeUsernameProblemLanguageResultExecution timeMemory
1093030BF001One-Way Streets (CEOI17_oneway)C++17
100 / 100
85 ms30848 KiB
#include<bits/stdc++.h> using namespace std; #define N 100005 #define fi first #define se second typedef pair<int, int> ii; int low[N], id[N], cnt, ncc, val[N], typ[N], n, m, dep[N]; vector<int> adj[N]; set<int> adj2[N]; stack<int> st; vector<ii> eg; void dfs(int u, int p){ low[u] = id[u] = ++cnt; st.push(u); for (auto x : adj[u]){ if (x == p){ p = -1; continue; } if (id[x]){ low[u] = min(low[u], id[x]); } else{ dfs(x, u); low[u] = min(low[u], low[x]); } } if (id[u] == low[u]){ ncc++; int s = -1; while (s != u){ s = st.top(); st.pop(); typ[s] = ncc; low[s] = id[s] = n + 1; } } } void getdep(int u, int p){ for (auto x : adj2[u]){ if (x == p) continue; dep[x] = dep[u] + 1; getdep(x, u); val[u] += val[x]; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n >> m; for (int i = 1; i <= m; i++){ int u, v; cin >> u >> v; eg.push_back({u, v}); adj[u].push_back(v); adj[v].push_back(u); } for (int i = 1; i <= n; i++){ if (!id[i]) dfs(i, 0); for (auto x : adj[i]){ if (typ[x] != typ[i]){ adj2[typ[x]].insert(typ[i]); adj2[typ[i]].insert(typ[x]); } } } int q; cin >> q; while (q--){ int a, b; cin >> a >> b; val[typ[a]]++; val[typ[b]]--; } for (int i = 1; i <= ncc; i++){ if (!dep[i]){ dep[i] = 1; getdep(i, 0); } } for (auto x : eg){ int a = typ[x.fi], b = typ[x.se]; if (a == b){ cout << "B"; continue; } if (dep[a] > dep[b]){ if (val[a] == 0){ cout << "B"; } if (val[a] > 0){ cout << "R"; } if (val[a] < 0){ cout << "L"; } } if (dep[a] < dep[b]){ if (val[b] == 0){ cout << "B"; } if (val[b] > 0){ cout << "L"; } if (val[b] < 0){ cout << "R"; } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...