This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")
//*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int , int> pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn = 3e6;
const ll mod = 1e9+7;
const ld PI = acos((ld)-1);
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
#define For(i,a,b) for(int i=a;i<=b;i++)
#define fi first
#define se second
int n,m,u,v,t,a[maxn],b[maxn],ans[maxn],dx[maxn];
vector<pair<int,int> >ke[maxn];
void dfs(int u,int x)
{
dx[u]=1;
for(auto p:ke[u])
{
int v=p.fi;
int y=p.se;
if(y!=-x)
{
if(!dx[v])
{
dfs(v,y);
a[u]+=a[v];
b[u]+=b[v];
}
else
if(dx[v]==1)
{
ans[abs(y)]=2;
b[u]++;
b[v]--;
}
}
}
if(b[u]>0||a[u]==0) ans[abs(x)]=2;
else
{
int v=a[u];
if(x<0)
{
x=-x;
v=-v;
}
if(v>0) ans[x]=1;
else ans[x]=3;
}
dx[u]=2;
}
int main()
{
cin >> n >> m;
For(i,1,m)
{
cin >> u >> v;
ke[u].push_back({v,i});
ke[v].push_back({u,-i});
}
cin >> t;
For(i,1,t)
{
cin >> u >> v;
a[u]++;
a[v]--;
}
For(i,1,n)
if(!dx[i])
dfs(i,0);
For(i,1,m)
{
if(ans[i]==1) cout<<'L';
if(ans[i]==2) cout<<'B';
if(ans[i]==3) cout<<'R';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |