# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
303099 | 2020-09-19T22:04:41 Z | Kenzo_1114 | One-Way Streets (CEOI17_oneway) | C++14 | 7 ms | 9728 KB |
#include<bits/stdc++.h> using namespace std; const int MAXN = 200010; int n, m, p, depth[MAXN], low[MAXN], id[MAXN], par[MAXN]; vector<int> graph[MAXN], edge[MAXN]; bool bridge[MAXN], marc[MAXN]; char ans[MAXN]; void dfs(int v, int p) { par[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; } } 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); if(u == v) 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); while(!marc[x] && par[x] != x) { if(bridge[id[x] / 2]) ans[id[x] / 2] = (id[x] % 2) ? 'R' : 'L'; marc[x] = true; x = par[x]; } while(!marc[y] && par[y] != y) { if(bridge[id[y] / 2]) ans[id[y] / 2] = (id[y] % 2) ? 'L' : 'R'; marc[y] = true; y = par[y]; } } for(int i = 0; i < m; i++) printf("%c", (ans[i] == 'L' || ans[i] == 'R') ? ans[i] : 'B'); 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 | - |