제출 #1032782

#제출 시각아이디문제언어결과실행 시간메모리
1032782amine_arouaOne-Way Streets (CEOI17_oneway)C++17
0 / 100
0 ms348 KiB
#include<bits/stdc++.h> using namespace std; vector<vector<pair<int , int>>> adj; vector<int> depth; vector<int> dp; vector<int> pref; vector<vector<int>> up; vector<char> ans; vector<pair<int ,int>> edges; void dfs(int x) { for(auto [u , i] : adj[x]) { if(depth[u] == 0) { up[0][u] = x; depth[u] = depth[x] + 1; for(int j = 1 ; j < 18 ; j++) { up[j][u] = up[j - 1][up[j - 1][u]]; } dfs(u); dp[x]+=dp[u]; } else if(depth[u] < depth[x]) { dp[x]++; } else { dp[x]--; } } dp[x]--; } void dfs1(int x) { for(auto [u , i] : adj[x]) { if(depth[u] == 0) { depth[u] = depth[x] + 1; dfs1(u); if(dp[u] == 0 && pref[u]) { int m1 = (u == edges[i].first ? 1 : -1); int m2 = (pref[u] > 0 ? 1 : -1); if(m1 * m2 > 0) { ans[i] = 'R'; } else ans[i] = 'L'; } pref[x]+=pref[u]; } } } void lift(int &u , int k) { for(int i = 0 ; i < 18 ; i++) { if((1<<i) & k) { u = up[i][u]; } } } int lca(int u , int v) { if(depth[u] < depth[v]) swap(u , v); int x = depth[u] - depth[v]; lift(u , x); if(u == v) return u; for(int j = 17 ; j >= 0 ; j--) { int nu = up[j][u] , nv = up[j][v]; if(nu == nv) continue; u = nu , v = nv; } return up[0][u]; } int main() { int n , m; cin>>n>>m; up.assign(18 , vector<int>(n + 1)); adj = vector<vector<pair<int, int>>> (n + 1); depth = vector<int> (n + 1); dp = depth; pref = depth; edges.assign(m , {}); ans.assign(m , 'B'); for(int i = 0 ; i < m; i++) { int x ,y; cin>>x>>y; edges[i] = {x , y}; adj[x].push_back({y , i}); adj[y].push_back({x , i}); } depth[1] = 1; dfs(1); int p ; cin>>p; for(int i = 0 ; i < p ; i++) { int x , y; cin>>x>>y; int l = lca(x , y); pref[x]++; pref[y]--; } depth.assign(n + 1 , 0); depth[1] = 1; dfs1(1); for(int i = 0 ;i < m; i++) cout<<ans[i]; }

컴파일 시 표준 에러 (stderr) 메시지

oneway.cpp: In function 'int main()':
oneway.cpp:113:13: warning: unused variable 'l' [-Wunused-variable]
  113 |         int l = lca(x , y);
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...