Submission #303097

#TimeUsernameProblemLanguageResultExecution timeMemory
303097Kenzo_1114One-Way Streets (CEOI17_oneway)C++17
0 / 100
4 ms4992 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN = 100010; 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 < 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); } 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(par[x] != x) { if(bridge[id[x] / 2]) ans[id[x] / 2] = (id[x] % 2) ? 'R' : 'L'; marc[x] = true; x = par[x]; } while(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 (stderr)

oneway.cpp: In function 'void dfs(int, int)':
oneway.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for(int i = 0; i < graph[v].size(); i++)
      |                 ~~^~~~~~~~~~~~~~~~~
oneway.cpp: In function 'int main()':
oneway.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |  scanf("%d", &p);
      |  ~~~~~^~~~~~~~~~
oneway.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   62 |   scanf("%d %d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...