/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define llll std::pair<ll , ll>
#define pb push_back
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
#define debug std::cout << "!!ALERT ALERT!!" << std::endl;
const ll limit = 1e18+7;
const ll sus = 1e5 + 5;
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll a , ll b){
return (rng() % (b-a+1)) + a;
}
/*global variables*/
ll n , m , p;
std::vector<ll> adj[sus];std::vector<llll> nadj[sus];
std::vector<std::pair<llll , ll>> eg;
ll vis[sus] , sz[sus] , par[sus];
ll deg[sus] , sdeg[sus] , ans[sus];
/**/
/*functions*/
ll fin(ll x){
if(par[x] == x){
return x;
}
return par[x] = fin(par[x]);
}
void mrg(ll x , ll y){
x = fin(x);y = fin(y);
if(x == y){
return;
}
if(sz[x] < sz[y]){
std::swap(x , y);
}
sz[x] += sz[y];
par[y] = x;
}
ll cycdfs(ll crt , ll prv){
vis[crt] = 1;
ll o = 0;
ll p = 0;
for(auto j:adj[crt]){
if(p == 0 && j == prv){
p = 1;
continue;
}
if(vis[j] == 0){
o += cycdfs(j , crt);
}
else if(vis[j] == 1){
o+=1;
deg[j]--;
}
}
o+=deg[crt];
//std::cout << crt << " " << prv << " " << o << "\n";
if(o > 0){
//debug;
mrg(crt , prv);
}
vis[crt] = 2;
return o;
}
ll sdfs(ll crt , ll prv , ll o){
ll sm = 0;
//std::cout << crt << " " << prv << " " << o << std::endl;
for(auto j:nadj[crt]){
if(j.fi == prv){
continue;
}
sm += sdfs(j.fi , crt , j.sec);
}
sm+=sdeg[crt];
if(o != -1){
if((eg[o].fi.fi == prv && sm > 0) || (eg[0].fi.fi != prv && sm < 0)){
ans[o] = 1;
}
else if(sm != 0){
ans[o] = -1;
}
}
return sm;
}
/**/
void solve(){
std::cin >> n >> m;
for(ll i = 0;n>=i;i++){
par[i] = i;
sz[i] = 1;
}
for(ll i=0;m>i;i++){
ll x , y;std::cin >> x >> y;
adj[x].pb(y);
adj[y].pb(x);
eg.pb({{x , y} , i});
}
for(ll i = 1;n>=i;i++){
if(vis[i] == 0){
cycdfs(i , 0);
}
}
for(ll i = 0;m>i;i++){
if(fin(eg[i].fi.fi) != fin(eg[i].fi.sec)){
//std::cout << fin(eg[i].fi.fi) << " " << fin(eg[i].fi.sec) << "\n";
nadj[fin(eg[i].fi.fi)].pb({fin(eg[i].fi.sec) , i});
nadj[fin(eg[i].fi.sec)].pb({fin(eg[i].fi.fi) , i});
}
}
std::cin >> p;
while(p--){
ll x , y;std::cin >> x >> y;
sdeg[fin(x)]++;
sdeg[fin(y)]--;
}
//std::cout << std::endl;
sdfs(fin(3) , 0 , -1);
for(ll i = 0;m>i;i++){
if(ans[i] > 0){
std::cout << "L";
}
else if(ans[i] < 0){
std::cout << "R";
}
else{
std::cout << "B";
}
}
return;/**/
}
int main(){
std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
/*#ifndef ONLINE_JUDGE
freopen("in.txt" , "r" , stdin);
freopen("out.txt" , "w" , stdout);
#endif*/
ll t = 1;
//std::cin >> t;
while(t--){
solve();
}
}
Compilation message
oneway.cpp:5:78: warning: "/*" within comment [-Wcomment]
5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |