/*
#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';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
70764 KB |
Output is correct |
2 |
Correct |
41 ms |
70764 KB |
Output is correct |
3 |
Correct |
43 ms |
70892 KB |
Output is correct |
4 |
Correct |
42 ms |
70892 KB |
Output is correct |
5 |
Correct |
42 ms |
70892 KB |
Output is correct |
6 |
Correct |
41 ms |
70892 KB |
Output is correct |
7 |
Correct |
47 ms |
70892 KB |
Output is correct |
8 |
Correct |
42 ms |
71020 KB |
Output is correct |
9 |
Correct |
42 ms |
70892 KB |
Output is correct |
10 |
Correct |
41 ms |
70892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
70764 KB |
Output is correct |
2 |
Correct |
41 ms |
70764 KB |
Output is correct |
3 |
Correct |
43 ms |
70892 KB |
Output is correct |
4 |
Correct |
42 ms |
70892 KB |
Output is correct |
5 |
Correct |
42 ms |
70892 KB |
Output is correct |
6 |
Correct |
41 ms |
70892 KB |
Output is correct |
7 |
Correct |
47 ms |
70892 KB |
Output is correct |
8 |
Correct |
42 ms |
71020 KB |
Output is correct |
9 |
Correct |
42 ms |
70892 KB |
Output is correct |
10 |
Correct |
41 ms |
70892 KB |
Output is correct |
11 |
Correct |
121 ms |
76524 KB |
Output is correct |
12 |
Correct |
133 ms |
77420 KB |
Output is correct |
13 |
Correct |
135 ms |
78480 KB |
Output is correct |
14 |
Correct |
173 ms |
79212 KB |
Output is correct |
15 |
Correct |
152 ms |
79212 KB |
Output is correct |
16 |
Correct |
144 ms |
77476 KB |
Output is correct |
17 |
Correct |
134 ms |
78828 KB |
Output is correct |
18 |
Correct |
176 ms |
77316 KB |
Output is correct |
19 |
Correct |
133 ms |
79980 KB |
Output is correct |
20 |
Correct |
125 ms |
77036 KB |
Output is correct |
21 |
Correct |
125 ms |
76908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
70764 KB |
Output is correct |
2 |
Correct |
41 ms |
70764 KB |
Output is correct |
3 |
Correct |
43 ms |
70892 KB |
Output is correct |
4 |
Correct |
42 ms |
70892 KB |
Output is correct |
5 |
Correct |
42 ms |
70892 KB |
Output is correct |
6 |
Correct |
41 ms |
70892 KB |
Output is correct |
7 |
Correct |
47 ms |
70892 KB |
Output is correct |
8 |
Correct |
42 ms |
71020 KB |
Output is correct |
9 |
Correct |
42 ms |
70892 KB |
Output is correct |
10 |
Correct |
41 ms |
70892 KB |
Output is correct |
11 |
Correct |
121 ms |
76524 KB |
Output is correct |
12 |
Correct |
133 ms |
77420 KB |
Output is correct |
13 |
Correct |
135 ms |
78480 KB |
Output is correct |
14 |
Correct |
173 ms |
79212 KB |
Output is correct |
15 |
Correct |
152 ms |
79212 KB |
Output is correct |
16 |
Correct |
144 ms |
77476 KB |
Output is correct |
17 |
Correct |
134 ms |
78828 KB |
Output is correct |
18 |
Correct |
176 ms |
77316 KB |
Output is correct |
19 |
Correct |
133 ms |
79980 KB |
Output is correct |
20 |
Correct |
125 ms |
77036 KB |
Output is correct |
21 |
Correct |
125 ms |
76908 KB |
Output is correct |
22 |
Correct |
192 ms |
79980 KB |
Output is correct |
23 |
Correct |
192 ms |
78572 KB |
Output is correct |
24 |
Correct |
205 ms |
78572 KB |
Output is correct |
25 |
Correct |
189 ms |
83180 KB |
Output is correct |
26 |
Correct |
196 ms |
79724 KB |
Output is correct |
27 |
Correct |
193 ms |
78572 KB |
Output is correct |
28 |
Correct |
127 ms |
74732 KB |
Output is correct |
29 |
Correct |
184 ms |
77804 KB |
Output is correct |
30 |
Correct |
179 ms |
77932 KB |
Output is correct |
31 |
Correct |
188 ms |
78316 KB |
Output is correct |
32 |
Correct |
185 ms |
80108 KB |
Output is correct |