# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
303104 | 2020-09-19T22:13:19 Z | Kenzo_1114 | One-Way Streets (CEOI17_oneway) | C++17 | 7 ms | 9728 KB |
#include<bits/stdc++.h> using namespace std; const int MAXN = 200010; const int MAXK = 21; int n, m, p, depth[MAXN], low[MAXN], id[MAXN], par[MAXN], dp[MAXK][MAXN]; vector<int> graph[MAXN], edge[MAXN]; bool bridge[MAXN], marc[MAXN]; char ans[MAXN]; void dfs(int v, int p) { par[v] = p; dp[0][v] = p; depth[v] = (v == p) ? 0 : depth[p] + 1; low[v] = depth[v]; bool first = false; for(int i = 0; i < (int) graph[v].size(); i++) { int u = graph[v][i]; int ed = edge[v][i]; id[u] = ed; if(low[u] != -1) { if(first || u != p) low[v] = min(low[v], depth[u]); if(u == p) first = true; continue; } dfs(u, v); low[v] = min(low[v], low[u]); if(depth[v] < low[u]) bridge[ed / 2] = true; } } void calc() { for(int k = 1; k < MAXK; k++) for(int i = 0; i < n; i++) dp[k][i] = dp[k - 1][dp[k - 1][i]]; } int lca(int a, int b) { if(a == b) return a; if(depth[a] >= depth[b]) swap(a, b); for(int k = MAXK - 1; k >= 0; k--) if(depth[dp[k][b]] >= depth[a]) b = dp[k][b]; if(a == b) return a; for(int k = MAXK - 1; k >= 0; k--) if(dp[k][a] != dp[k][b]) a = dp[k][a], b = dp[k][b]; return dp[0][a]; } int main () { scanf("%d %d", &n, &m); for(int i = 0; i <= n; i++) low[i] = -1; for(int i = 0, u, v; i < m; i++) { scanf("%d %d", &u, &v); graph[u].push_back(v); graph[v].push_back(u); edge[u].push_back(2 * i); edge[v].push_back(2 * i + 1); ans[i] = 'B'; } dfs(1, 1); // for(int i = 0; i < m; i++) // if(bridge[i]) printf("edge %d is bridge\n", i); scanf("%d", &p); for(int i = 0, x, y; i < p; i++) { scanf("%d %d", &x, &y); int LCA = lca(x, y); while(x != LCA) { if(bridge[id[x] / 2]) ans[id[x] / 2] = (id[x] % 2) ? 'R' : 'L'; x = par[x]; } while(y != LCA) { if(bridge[id[y] / 2]) ans[id[y] / 2] = (id[y] % 2) ? 'L' : 'R'; y = par[y]; } } for(int i = 0; i < m; i++) printf("%c", ans[i]); printf("\n"); } /* 5 6 1 2 1 2 4 3 2 3 1 3 5 1 2 4 5 1 3 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 9728 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 9728 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 9728 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |