#include<bits/stdc++.h>
using namespace std;
vector<vector<pair<int , int>>> adj;
vector<int> depth;
vector<int> dp;
vector<int> pref;
vector<char> ans;
vector<pair<int ,int>> edges;
void dfs(int x)
{
for(auto [u , i] : adj[x])
{
if(depth[u] == 0)
{
depth[u] = depth[x] + 1;
dfs(u);
dp[x]+=dp[u];
}
else if(depth[u] < depth[x])
{
dp[x]++;
}
else if(depth[u] > depth[x])
{
dp[x]--;
}
}
dp[x]--;
}
void dfs1(int x)
{
for(auto [u , i] : adj[x])
{
if(depth[u] == 0)
{
depth[u] = depth[x] + 1;
dfs1(u);
if(dp[u] == 0 && pref[u])
{
int m1 = (u == edges[i].first ? 1 : -1);
int m2 = (pref[u] > 0 ? 1 : -1);
if(m1 * m2 > 0)
{
ans[i] = 'R';
}
else
ans[i] = 'L';
}
pref[x]+=pref[u];
}
}
}
int main()
{
int n , m;
cin>>n>>m;
adj = vector<vector<pair<int, int>>> (n + 1);
depth = vector<int> (n + 1);
dp = depth;
pref = depth;
edges.assign(m , {});
ans.assign(m , 'B');
for(int i = 0 ; i < m; i++)
{
int x ,y;
cin>>x>>y;
edges[i] = {x , y};
adj[x].push_back({y , i});
adj[y].push_back({x , i});
}
for(int i = 1 ; i <= n ; i++)
{
if(depth[i] == 0)
{
depth[i] = 1;
dfs(i);
}
}
int p ;
cin>>p;
for(int i = 0 ; i < p ; i++)
{
int x , y;
cin>>x>>y;
pref[x]++;
pref[y]--;
}
depth.assign(n + 1 , 0);
for(int i = 1; i <= n ; i++)
{
if(depth[i] == 0)
{
depth[i] = 1;
dfs1(i);
}
}
for(int i = 0 ;i < m; i++)
cout<<ans[i];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
43 ms |
7004 KB |
Output is correct |
12 |
Correct |
49 ms |
8020 KB |
Output is correct |
13 |
Correct |
52 ms |
9556 KB |
Output is correct |
14 |
Correct |
55 ms |
11024 KB |
Output is correct |
15 |
Correct |
55 ms |
11400 KB |
Output is correct |
16 |
Correct |
50 ms |
9812 KB |
Output is correct |
17 |
Correct |
53 ms |
11172 KB |
Output is correct |
18 |
Correct |
53 ms |
9640 KB |
Output is correct |
19 |
Correct |
50 ms |
12372 KB |
Output is correct |
20 |
Correct |
50 ms |
8244 KB |
Output is correct |
21 |
Correct |
52 ms |
8020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
43 ms |
7004 KB |
Output is correct |
12 |
Correct |
49 ms |
8020 KB |
Output is correct |
13 |
Correct |
52 ms |
9556 KB |
Output is correct |
14 |
Correct |
55 ms |
11024 KB |
Output is correct |
15 |
Correct |
55 ms |
11400 KB |
Output is correct |
16 |
Correct |
50 ms |
9812 KB |
Output is correct |
17 |
Correct |
53 ms |
11172 KB |
Output is correct |
18 |
Correct |
53 ms |
9640 KB |
Output is correct |
19 |
Correct |
50 ms |
12372 KB |
Output is correct |
20 |
Correct |
50 ms |
8244 KB |
Output is correct |
21 |
Correct |
52 ms |
8020 KB |
Output is correct |
22 |
Correct |
80 ms |
12372 KB |
Output is correct |
23 |
Correct |
82 ms |
10832 KB |
Output is correct |
24 |
Correct |
82 ms |
10736 KB |
Output is correct |
25 |
Correct |
82 ms |
15424 KB |
Output is correct |
26 |
Correct |
117 ms |
11988 KB |
Output is correct |
27 |
Correct |
82 ms |
10944 KB |
Output is correct |
28 |
Correct |
43 ms |
4692 KB |
Output is correct |
29 |
Correct |
78 ms |
8904 KB |
Output is correct |
30 |
Correct |
78 ms |
9044 KB |
Output is correct |
31 |
Correct |
79 ms |
9300 KB |
Output is correct |
32 |
Correct |
75 ms |
11484 KB |
Output is correct |