제출 #1304878

#제출 시각아이디문제언어결과실행 시간메모리
1304878neonglitchOne-Way Streets (CEOI17_oneway)C++20
0 / 100
3093 ms332 KiB
#include <iostream> #include <vector> #include <map> using namespace std; const int N=1e5+10; pair<int,int> edge[N]; int h[N],lw[N],par[N]; bool vis[N],bri[N]; char dir[N]; vector<pair<int,int>> adj[N]; void dfs(int x,int pid=0) { vis[x]=1; lw[x]=h[x]; for(auto [y,id]:adj[x]) { if(pid==id)continue; if(!vis[y]) { h[y]=h[x]+1; par[y]=x; dfs(y,id); if(lw[y]<h[y]) { // cout<<"Non bridge "<<id<<endl; bri[id]=0; } lw[x]=min(lw[x],lw[y]); } else{ // y is ancestor of x // cout<<"Edge "<<id<<' '<<x<<' '<<y<<endl; bri[id]=0; lw[x]=min(lw[x],h[y]); } } // cout<<"At "<<x<<' '<<h[x]<<' '<<lw[x]<<endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin>>n>>m; for(int j=1;j<=m;j++) { int x,y; cin>>x>>y; edge[j]={x,y}; adj[x].push_back({y,j}); adj[y].push_back({x,j}); bri[j]=(x!=y); } dfs(1); int p; cin>>p; map<pair<int,int>,bool> use; for(int i=0;i<p;i++) { int x,y; cin>>x>>y; while(x!=y) { if(h[x]>h[y]) { // edge x to par[x] should be use[{x,par[x]}]=1; x=par[x]; } else{ use[{par[y],y}]=1; y=par[y]; } } } for(int j=1;j<=m;j++) { if(!bri[j])cout<<'B'; else if(use[edge[j]])cout<<'R'; else cout<<'L'; } cout<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...