This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int const N=2e5+5;
vector<int> adj[N];
int n,m;
bool vis[N];
bool inpath[N];
int cnt[N];
map<pair<int,int>,int> mp;
void dfs1(int node,int par){
// cout<<node<<endl;
vis[node]=1;
inpath[node]=1;
bool p=1;
for(auto i:adj[node]){
if(vis[i]==0){
dfs1(i,node);
cnt[node]+=cnt[i];
if(cnt[i]>0){
mp[{i,node}]='B';
mp[{node,i}]='B';
}
}
else if(i==par && p==1)
p=0;
else if(inpath[i]){
cnt[node]++;
cnt[i]--;
mp[{node,i}]='B';
mp[{i,node}]='B';
}
}
inpath[node]=0;
}
vector<int> path;
int des=0;
void dfs(int node){
path.push_back(node);
vis[node]=1;
if(node==des){
des=-1;
int sz=path.size();
for(int i=0;i<sz-1;i++){
if(mp[{path[i],path[i+1]}]==' ')
mp[{path[i],path[i+1]}]='D';
}
}
for(auto i:adj[node]){
if(vis[i]==0)
dfs(i);
}
path.pop_back();
}
int main(){
cin>>n>>m;
vector<pair<int,int>> edge;
for (int i = 0; i < m; ++i){
int u,v;
cin>>u>>v;
edge.push_back({u,v});
mp[{u,v}]=' ';
mp[{v,u}]=' ';
if(u==v)
continue;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=1;i<=n;i++)
if(vis[i]==0)
dfs1(1,0);
int k;
cin>>k;
for (int i = 0; i < k; ++i){
int a,b;
cin>>a>>b;
des=b;
for(int j=0;j<=n;j++)
vis[j]=0;
path.clear();
dfs(a);
}
for(auto ed:edge){
int u=ed.first;
int v=ed.second;
if(mp[ed]=='D')
cout<<'R';
else if(mp[{v,u}]=='D')
cout<<'L';
else
cout<<'B';
}
cout<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |