#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
void usaco()
{
freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
// freopen("problem.out", "w", stdout);
}
vector<vii> graph;
vii edge;
vb dfstree;
vb vis;
void dfs(int x) {
vis[x] = true;
for(auto e : graph[x]) {
if(!vis[e.f] && e.f != x) {
dfstree[e.s] = true;
dfs(e.f);
}
}
}
vb bridg;
vector<vii> tree;
vb on;
vi dp;
vi pos;
int c = 0;
void dfs2(int x, int p) {
vis[x] = true;
for(auto e : graph[x]) {
if(!dfstree[e.s] && e.f != x) {
if(!vis[e.f]) {
dp[x]--;
}
else {
dp[x]++;
}
}
}
for(auto e : tree[x]) {
if(e.f != p && e.f != x) {
dfs2(e.f, x);
dp[x] += dp[e.f];
pos[e.f] = e.s;
}
}
}
vi out;
vii val;
vi en, st;
void assg(int a, int b, int id) {
if(edge[id].f == a) out[id] = 1;
else out[id] = -1;
}
int dfs3(int x, int p) {
vis[x] = true;
int c1 = 0;
c1 += st[x];
c1 -= en[x];
for(auto e : tree[x]) {
if(e.f != p && e.f != x) {
int v = dfs3(e.f, x);
if(bridg[e.s]) {if(v > 0) {
assg(e.f, x, e.s);
}
else if(v < 0) assg(x, e.f, e.s);}
c1 += v;
}
}
return c1;
}
int main() {
// usaco();
int n, m, p;
scd(n);
scd(m);
graph = vector<vii>(n+1);
dfstree = vb(m);
edge = vii(m);
frange(i, m) {
int a, b;
scd(a);
scd(b);
graph[a].pb(mp(b, i));
graph[b].pb(mp(a, i));
edge[i] = mp(a, b);
}
vis = vb(n+1);
forr(i, 1, n+1) {
if(!vis[i]) dfs(i);
}
bridg = vb(m);
tree = vector<vii>(n+1);
frange(i, m) {
if(dfstree[i]) {
int a= edge[i].f;
int b = edge[i].s;
tree[a].pb(mp(b, i));
tree[b].pb(mp(a, i));
bridg[i] = true;
}
}
on = vb(m);
vis = vb(n+1);
pos = dp = vi(n+1);
forr(i, 1, n+1) {
c = 0;
if(!vis[i]) dfs2(i, 0);
}
forr(i, 1, n+1) {
// printf("%d ", dp[i]);
if(dp[i]) bridg[pos[i]] = false;
}
// frange(i, m) {
// if(bridg[i]) printf("%d %d\n", edge[i].f, edge[i].s);
// }
st = en = vi(n+1);
scd(p);
val = vii(p);
frange(i, p) {
scd(val[i].f);
scd(val[i].s);
// printf("%d %d\n", val[i].f, val[i].s);
st[val[i].f]++;
en[val[i].s]++;
}
out = vi(m);
vis = vb(n+1);
forr(i, 1, n+1) {
if(!vis[i]) {
dfs3(i, 0);
}
}
for(auto e : out) {
if(e == 1) printf("R");
else if(e == -1) printf("L");
else printf("B");
}
}
Compilation message
oneway.cpp: In function 'void usaco()':
oneway.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp: In function 'int main()':
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
oneway.cpp:111:5: note: in expansion of macro 'scd'
111 | scd(n);
| ^~~
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
oneway.cpp:112:5: note: in expansion of macro 'scd'
112 | scd(m);
| ^~~
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
oneway.cpp:120:9: note: in expansion of macro 'scd'
120 | scd(a);
| ^~~
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
oneway.cpp:121:9: note: in expansion of macro 'scd'
121 | scd(b);
| ^~~
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
oneway.cpp:165:5: note: in expansion of macro 'scd'
165 | scd(p);
| ^~~
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
oneway.cpp:168:9: note: in expansion of macro 'scd'
168 | scd(val[i].f);
| ^~~
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
oneway.cpp:169:9: note: in expansion of macro 'scd'
169 | scd(val[i].s);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
32 ms |
8004 KB |
Output is correct |
12 |
Correct |
39 ms |
10068 KB |
Output is correct |
13 |
Correct |
48 ms |
12880 KB |
Output is correct |
14 |
Correct |
60 ms |
15952 KB |
Output is correct |
15 |
Correct |
58 ms |
16720 KB |
Output is correct |
16 |
Correct |
54 ms |
16488 KB |
Output is correct |
17 |
Correct |
72 ms |
18072 KB |
Output is correct |
18 |
Correct |
84 ms |
16448 KB |
Output is correct |
19 |
Correct |
61 ms |
19132 KB |
Output is correct |
20 |
Correct |
52 ms |
11580 KB |
Output is correct |
21 |
Correct |
56 ms |
11328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
32 ms |
8004 KB |
Output is correct |
12 |
Correct |
39 ms |
10068 KB |
Output is correct |
13 |
Correct |
48 ms |
12880 KB |
Output is correct |
14 |
Correct |
60 ms |
15952 KB |
Output is correct |
15 |
Correct |
58 ms |
16720 KB |
Output is correct |
16 |
Correct |
54 ms |
16488 KB |
Output is correct |
17 |
Correct |
72 ms |
18072 KB |
Output is correct |
18 |
Correct |
84 ms |
16448 KB |
Output is correct |
19 |
Correct |
61 ms |
19132 KB |
Output is correct |
20 |
Correct |
52 ms |
11580 KB |
Output is correct |
21 |
Correct |
56 ms |
11328 KB |
Output is correct |
22 |
Correct |
67 ms |
19792 KB |
Output is correct |
23 |
Correct |
96 ms |
18288 KB |
Output is correct |
24 |
Correct |
89 ms |
18384 KB |
Output is correct |
25 |
Correct |
77 ms |
22768 KB |
Output is correct |
26 |
Correct |
67 ms |
19332 KB |
Output is correct |
27 |
Correct |
68 ms |
18260 KB |
Output is correct |
28 |
Correct |
30 ms |
5456 KB |
Output is correct |
29 |
Correct |
59 ms |
13264 KB |
Output is correct |
30 |
Correct |
54 ms |
13396 KB |
Output is correct |
31 |
Correct |
60 ms |
13712 KB |
Output is correct |
32 |
Correct |
63 ms |
16724 KB |
Output is correct |