Submission #303943

#TimeUsernameProblemLanguageResultExecution timeMemory
303943peuchOne-Way Streets (CEOI17_oneway)C++17
100 / 100
229 ms33272 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN = 100010; int n, m, p; int low[MAXN], pre[MAXN]; int cnt; int bridge[MAXN]; pair<int, int> edge[MAXN]; int rep[MAXN], tam[MAXN]; int auxSum[MAXN]; int marc[MAXN]; int ans[MAXN]; vector<int> ar[MAXN], id[MAXN]; vector<int> tree[MAXN], treeID[MAXN]; void dfs(int cur, int pai); void uni(int a, int b); int find(int a); void endCalc(int cur, int pai); int main(){ scanf("%d %d", &n, &m); for(int i = 1; i <= n; i++) rep[i] = i, tam[i] = 1; for(int i = 1; i <= m; i++){ int a, b; scanf("%d %d", &a, &b); ar[a].push_back(b); ar[b].push_back(a); id[a].push_back(i); id[b].push_back(i); edge[i] = make_pair(a, b); } for(int i = 1; i <= n; i++) if(marc[i] != 1) dfs(i, 0); for(int i = 1; i <= m; i++){ if(bridge[i]) continue; uni(edge[i].first, edge[i].second); } for(int i = 1; i <= m; i++){ if(!bridge[i]) continue; int a = edge[i].first; int b = edge[i].second; a = find(a); b = find(b); tree[a].push_back(b); tree[b].push_back(a); treeID[a].push_back(i); treeID[b].push_back(i); } scanf("%d", &p); for(int i = 1; i <= p; i++){ int a, b; scanf("%d %d", &a, &b); a = find(a); b = find(b); auxSum[a]++; auxSum[b]--; } for(int i = 1; i <= n; i++) if(marc[find(i)] != 2) endCalc(find(i), 0); for(int i = 1; i <= m; i++){ if(ans[i] == 1) printf("R"); else if(ans[i] == -1) printf("L"); else printf("B"); } printf("\n"); return 0; } void dfs(int cur, int pai){ marc[cur] = 1; pre[cur] = low[cur] = ++cnt; for(int i = 0; i < ar[cur].size(); i++){ int viz = ar[cur][i]; if(id[cur][i] == pai) continue; if(pre[viz] != 0) low[cur] = min(low[cur], pre[viz]); else{ dfs(viz, id[cur][i]); if(low[viz] > pre[cur]) bridge[id[cur][i]] = 1; low[cur] = min(low[cur], low[viz]); } } } void uni(int a, int b){ a = find(a); b = find(b); if(a == b) return; if(tam[a] > tam[b]) tam[a] += tam[b], rep[b] = a; else tam[b] += tam[a], rep[a] = b; } int find(int a){ if(rep[a] == a) return a; return rep[a] = find(rep[a]); } void endCalc(int cur, int pai){ marc[cur] = 2; for(int i = 0; i < tree[cur].size(); i++){ int viz = tree[cur][i]; int eID = treeID[cur][i]; if(viz == pai) continue; endCalc(viz, cur); if(auxSum[viz] < 0){ if(find(edge[eID].first) == cur) ans[eID] = 1; else ans[eID] = -1; } else if(auxSum[viz] > 0){ if(find(edge[eID].first) == cur) ans[eID] = -1; else ans[eID] = 1; } auxSum[cur] += auxSum[viz]; } }

Compilation message (stderr)

oneway.cpp: In function 'void dfs(int, int)':
oneway.cpp:86:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |  for(int i = 0; i < ar[cur].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~~
oneway.cpp: In function 'void endCalc(int, int)':
oneway.cpp:115:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |  for(int i = 0; i < tree[cur].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~~~~
oneway.cpp: In function 'int main()':
oneway.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |   scanf("%d %d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |  scanf("%d", &p);
      |  ~~~~~^~~~~~~~~~
oneway.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   64 |   scanf("%d %d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...