//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n,m,q;
vector<ii> al[100005];
int dfs_time[100005];
int low[100005];
set<int> s[100005];
int ans[100005];
int TIME=1;
void dfs(int i,int p){
dfs_time[i]=low[i]=TIME++;
for (auto &it:al[i]){
if (it.se==~p) continue;
if (!dfs_time[it.fi]){
dfs(it.fi,it.se);
low[i]=min(low[i],low[it.fi]);
//merge sets
if (sz(s[it.fi])>sz(s[i])) swap(s[it.fi],s[i]);
for (auto &val:s[it.fi]){
if (s[i].count(~val)) s[i].erase(~val);
else s[i].insert(val);
}
}
else{
low[i]=min(low[i],dfs_time[it.fi]);
}
}
int rp=(p>=0?p:~p);
if (low[i]==dfs_time[i] && !s[i].empty()){
if (((*s[i].begin())>=0)==(p>=0)) ans[rp]=1;
else ans[rp]=2;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
int a,b;
rep(x,0,m){
cin>>a>>b;
al[a].push_back(ii(b,x));
al[b].push_back(ii(a,~x));
}
cin>>q;
rep(x,0,q){
cin>>a>>b;
if (a==b) continue; //think
s[a].insert(x);
s[b].insert(~x);
}
rep(x,1,n+1) if (!dfs_time[x]){
dfs(x,1e9);
}
rep(x,0,m){
if (ans[x]==1) cout<<"L";
else if (ans[x]==2) cout<<"R";
else cout<<"B";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7552 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
9 ms |
7552 KB |
Output is correct |
6 |
Correct |
9 ms |
7552 KB |
Output is correct |
7 |
Correct |
9 ms |
7552 KB |
Output is correct |
8 |
Correct |
9 ms |
7424 KB |
Output is correct |
9 |
Correct |
9 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
7552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7552 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
9 ms |
7552 KB |
Output is correct |
6 |
Correct |
9 ms |
7552 KB |
Output is correct |
7 |
Correct |
9 ms |
7552 KB |
Output is correct |
8 |
Correct |
9 ms |
7424 KB |
Output is correct |
9 |
Correct |
9 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
7552 KB |
Output is correct |
11 |
Correct |
61 ms |
14584 KB |
Output is correct |
12 |
Correct |
64 ms |
15736 KB |
Output is correct |
13 |
Correct |
68 ms |
16888 KB |
Output is correct |
14 |
Correct |
73 ms |
17400 KB |
Output is correct |
15 |
Correct |
78 ms |
17272 KB |
Output is correct |
16 |
Correct |
68 ms |
13432 KB |
Output is correct |
17 |
Correct |
67 ms |
16504 KB |
Output is correct |
18 |
Correct |
86 ms |
13816 KB |
Output is correct |
19 |
Correct |
65 ms |
18296 KB |
Output is correct |
20 |
Correct |
64 ms |
14712 KB |
Output is correct |
21 |
Correct |
57 ms |
14712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7552 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
9 ms |
7552 KB |
Output is correct |
6 |
Correct |
9 ms |
7552 KB |
Output is correct |
7 |
Correct |
9 ms |
7552 KB |
Output is correct |
8 |
Correct |
9 ms |
7424 KB |
Output is correct |
9 |
Correct |
9 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
7552 KB |
Output is correct |
11 |
Correct |
61 ms |
14584 KB |
Output is correct |
12 |
Correct |
64 ms |
15736 KB |
Output is correct |
13 |
Correct |
68 ms |
16888 KB |
Output is correct |
14 |
Correct |
73 ms |
17400 KB |
Output is correct |
15 |
Correct |
78 ms |
17272 KB |
Output is correct |
16 |
Correct |
68 ms |
13432 KB |
Output is correct |
17 |
Correct |
67 ms |
16504 KB |
Output is correct |
18 |
Correct |
86 ms |
13816 KB |
Output is correct |
19 |
Correct |
65 ms |
18296 KB |
Output is correct |
20 |
Correct |
64 ms |
14712 KB |
Output is correct |
21 |
Correct |
57 ms |
14712 KB |
Output is correct |
22 |
Correct |
380 ms |
38368 KB |
Output is correct |
23 |
Correct |
348 ms |
52732 KB |
Output is correct |
24 |
Correct |
392 ms |
55312 KB |
Output is correct |
25 |
Correct |
324 ms |
37880 KB |
Output is correct |
26 |
Correct |
355 ms |
37624 KB |
Output is correct |
27 |
Correct |
389 ms |
44280 KB |
Output is correct |
28 |
Correct |
208 ms |
22520 KB |
Output is correct |
29 |
Correct |
307 ms |
36472 KB |
Output is correct |
30 |
Correct |
306 ms |
36268 KB |
Output is correct |
31 |
Correct |
306 ms |
32760 KB |
Output is correct |
32 |
Correct |
250 ms |
32632 KB |
Output is correct |