# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
43122 | 2018-03-09T09:47:02 Z | win11905 | One-Way Streets (CEOI17_oneway) | C++11 | 3000 ms | 10108 KB |
#include <bits/stdc++.h> #define pii pair<int, int> #define x first #define y second using namespace std; const int MAXN = 1e5 + 5; vector<pii> g[MAXN]; int n, m, par[MAXN][18], dep[MAXN], d1[MAXN], d2[MAXN]; char ans[MAXN]; bool chk[MAXN]; pii E[MAXN]; void dfs(int u, int p) { dep[u] = dep[p] + 1; par[u][0] = p; for(int i = 1; i <= 17; ++i) par[u][i] = par[par[u][i-1]][i-1]; for(auto v : g[u]) if(par[v.x][0] == -1) { chk[v.y] = true; dfs(v.x, u); } } int lca(int a, int b) { if(dep[a] < dep[b]) swap(a, b); for(int i = 17; i >= 0; --i) if(dep[par[a][i]] >= dep[b]) a = par[a][i]; if(a == b) return a; for(int i = 17; i >= 0; --i) if(par[a][i] != par[b][i]) a = par[a][i], b= par[b][i]; return par[a][0]; } void dfs1(int u) { for(auto v : g[u]) if(par[v.x][0] == u) { dfs1(v.x); d1[u] += d1[v.x], d2[u] += d2[v.x]; ans[v.y] = 'B'; int node = -1; if(d2[v.x] > 0) node = v.x; if(d2[v.x] < 0) node = u; if(node == -1 || d1[v.x]) continue; if(node == E[v.y].x) ans[v.y] = 'R'; else ans[v.y] = 'L'; } } int main() { #ifdef INPUT freopen("r", "r", stdin); #endif memset(par, -1, sizeof par); scanf("%d %d", &n, &m); for(int i = 1; i <= m; ++i) { int u, v; scanf("%d %d", &u, &v); g[u].emplace_back(v, i); g[v].emplace_back(u, i); E[i] = pii(u, v); } for(int i = 1; i <= n; ++i) if(par[i][0] == -1) dfs(i, 0); for(int i = 1; i <= m; ++i) if(!chk[i]) d1[E[i].x]++, d1[E[i].y]++, d1[lca(E[i].x, E[i].y)] -= 2, ans[i] = 'B'; int t; scanf("%d", &t); while(t--) { int a, b; scanf("%d %d", &a, &b); d2[a]++, d2[b]--; } for(int i = 1; i <= n; ++i) if(!par[i][0]) dfs1(i); printf("%s\n", ans+1); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9720 KB | Output is correct |
2 | Correct | 8 ms | 9908 KB | Output is correct |
3 | Correct | 9 ms | 10108 KB | Output is correct |
4 | Correct | 9 ms | 10108 KB | Output is correct |
5 | Correct | 9 ms | 10108 KB | Output is correct |
6 | Execution timed out | 3017 ms | 10108 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9720 KB | Output is correct |
2 | Correct | 8 ms | 9908 KB | Output is correct |
3 | Correct | 9 ms | 10108 KB | Output is correct |
4 | Correct | 9 ms | 10108 KB | Output is correct |
5 | Correct | 9 ms | 10108 KB | Output is correct |
6 | Execution timed out | 3017 ms | 10108 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9720 KB | Output is correct |
2 | Correct | 8 ms | 9908 KB | Output is correct |
3 | Correct | 9 ms | 10108 KB | Output is correct |
4 | Correct | 9 ms | 10108 KB | Output is correct |
5 | Correct | 9 ms | 10108 KB | Output is correct |
6 | Execution timed out | 3017 ms | 10108 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |