#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 100005, l = 20;
int n, m;
pair<int, int> r[N];
vector<int> a[N];
vector<int> b[N];
bool bri[N];
int c[N];
int tin[N], ti, fup[N];
void dfs0(int x, int p)
{
c[x] = 1;
fup[x] = tin[x] = ti++;
for (int i = 0; i < a[x].size(); ++i)
{
int h = a[x][i];
if (h == p)
continue;
if (c[h])
fup[x] = min(fup[x], tin[h]);
else
{
dfs0(h, x);
if (fup[h] > tin[x])
bri[b[x][i]] = true;
fup[x] = min(fup[x], fup[h]);
}
}
}
int k;
void dfs1(int x)
{
c[x] = k;
for (int i = 0; i < a[x].size(); ++i)
{
if (bri[b[x][i]])
continue;
int h = a[x][i];
if (!c[h])
dfs1(h);
}
}
vector<int> g[N];
vector<int> gg[N];
bool c1[N];
int tout[N];
int pp[N][l];
bool dfs(int x, int p)
{
c1[x] = true;
tin[x] = ti++;
pp[x][0] = p;
for (int i = 1; i < l; ++i)
{
pp[x][i] = pp[pp[x][i - 1]][i - 1];
}
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
if (h == p)
continue;
dfs(h, x);
}
tout[x] = ti++;
}
bool par(int x, int y)
{
return (tin[x] <= tin[y] && tout[x] >= tout[y]);
}
int lca(int x, int y)
{
if (par(x, y))
return x;
if (par(y, x))
return y;
for (int i = l - 1; i >= 0; --i)
{
if (!par(pp[x][i], y))
x = pp[x][i];
}
return pp[x][0];
}
char ans[N];
int qu[N], qd[N];
void dfsf(int x, int p, int j)
{
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
if (h == p)
continue;
dfsf(h, x, gg[x][i]);
qu[x] += qu[h];
qd[x] += qd[h];
}
if (qu[x])
{
if (m_p(x, p) == m_p(c[r[j].first], c[r[j].second]))
ans[j - 1] = 'R';
else
ans[j - 1] = 'L';
}
if (qd[x])
{
if (m_p(p, x) == m_p(c[r[j].first], c[r[j].second]))
ans[j - 1] = 'R';
else
ans[j - 1] = 'L';
}
}
int main()
{
//freopen("input.txt", "r", stdin);
map<pair<int, int> , int> mp;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; ++i)
{
int x, y;
scanf("%d%d", &x, &y);
a[x].push_back(y);
a[y].push_back(x);
b[x].push_back(i);
b[y].push_back(i);
r[i] = m_p(x, y);
if (x > y)
swap(x, y);
mp[m_p(x, y)]++;
}
for (int i = 1; i <= n; ++i)
{
if (!c[i])
dfs0(i, -1);
}
for (int i = 1; i <= m; ++i)
{
if (bri[i])
{
if (mp[m_p(min(r[i].first, r[i].second), max(r[i].first, r[i].second))] > 1)
bri[i] = false;
}
}
memset(c, 0, sizeof c);
for (int x = 1; x <= n; ++x)
{
if (!c[x])
{
++k;
dfs1(x);
}
}
for (int x = 1; x <= n; ++x)
{
for (int i = 0; i < a[x].size(); ++i)
{
if (bri[b[x][i]])
{
g[c[x]].push_back(c[a[x][i]]);
gg[c[x]].push_back(b[x][i]);
}
}
}
for (int i = 1; i <= m; ++i)
ans[i - 1] = 'B';
vector<int> v;
for (int i = 1; i <= k; ++i)
{
if (!c1[i])
{
v.push_back(i);
dfs(i, i);
}
}
int q;
scanf("%d", &q);
while (q--)
{
int x, y;
scanf("%d%d", &x, &y);
x = c[x];
y = c[y];
int t = lca(x, y);
qu[x]++;
qu[t]--;
qd[y]++;
qd[t]--;
}
for (int i = 0; i < v.size(); ++i)
{
dfsf(v[i], v[i], -1);
}
cout << ans << endl;
return 0;
}
Compilation message
oneway.cpp: In function 'void dfs0(int, int)':
oneway.cpp:19:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a[x].size(); ++i)
~~^~~~~~~~~~~~~
oneway.cpp: In function 'void dfs1(int)':
oneway.cpp:40:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a[x].size(); ++i)
~~^~~~~~~~~~~~~
oneway.cpp: In function 'bool dfs(int, int)':
oneway.cpp:64:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[x].size(); ++i)
~~^~~~~~~~~~~~~
oneway.cpp:72:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
oneway.cpp: In function 'void dfsf(int, int, int)':
oneway.cpp:96:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[x].size(); ++i)
~~^~~~~~~~~~~~~
oneway.cpp: In function 'int main()':
oneway.cpp:164:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a[x].size(); ++i)
~~^~~~~~~~~~~~~
oneway.cpp:201:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < v.size(); ++i)
~~^~~~~~~~~~
oneway.cpp:125:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
oneway.cpp:129:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &x, &y);
~~~~~^~~~~~~~~~~~~~~~
oneway.cpp:188:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &q);
~~~~~^~~~~~~~~~
oneway.cpp:192:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &x, &y);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
10104 KB |
Output is correct |
2 |
Correct |
11 ms |
10104 KB |
Output is correct |
3 |
Correct |
12 ms |
10232 KB |
Output is correct |
4 |
Correct |
12 ms |
10488 KB |
Output is correct |
5 |
Correct |
13 ms |
10488 KB |
Output is correct |
6 |
Correct |
12 ms |
10232 KB |
Output is correct |
7 |
Correct |
12 ms |
10488 KB |
Output is correct |
8 |
Correct |
12 ms |
10420 KB |
Output is correct |
9 |
Correct |
12 ms |
10232 KB |
Output is correct |
10 |
Correct |
12 ms |
10232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
10104 KB |
Output is correct |
2 |
Correct |
11 ms |
10104 KB |
Output is correct |
3 |
Correct |
12 ms |
10232 KB |
Output is correct |
4 |
Correct |
12 ms |
10488 KB |
Output is correct |
5 |
Correct |
13 ms |
10488 KB |
Output is correct |
6 |
Correct |
12 ms |
10232 KB |
Output is correct |
7 |
Correct |
12 ms |
10488 KB |
Output is correct |
8 |
Correct |
12 ms |
10420 KB |
Output is correct |
9 |
Correct |
12 ms |
10232 KB |
Output is correct |
10 |
Correct |
12 ms |
10232 KB |
Output is correct |
11 |
Correct |
159 ms |
22904 KB |
Output is correct |
12 |
Correct |
182 ms |
24144 KB |
Output is correct |
13 |
Correct |
233 ms |
26104 KB |
Output is correct |
14 |
Correct |
285 ms |
30596 KB |
Output is correct |
15 |
Correct |
288 ms |
32476 KB |
Output is correct |
16 |
Correct |
361 ms |
41464 KB |
Output is correct |
17 |
Correct |
334 ms |
42736 KB |
Output is correct |
18 |
Correct |
456 ms |
41464 KB |
Output is correct |
19 |
Correct |
336 ms |
44024 KB |
Output is correct |
20 |
Correct |
181 ms |
24056 KB |
Output is correct |
21 |
Correct |
147 ms |
23676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
10104 KB |
Output is correct |
2 |
Correct |
11 ms |
10104 KB |
Output is correct |
3 |
Correct |
12 ms |
10232 KB |
Output is correct |
4 |
Correct |
12 ms |
10488 KB |
Output is correct |
5 |
Correct |
13 ms |
10488 KB |
Output is correct |
6 |
Correct |
12 ms |
10232 KB |
Output is correct |
7 |
Correct |
12 ms |
10488 KB |
Output is correct |
8 |
Correct |
12 ms |
10420 KB |
Output is correct |
9 |
Correct |
12 ms |
10232 KB |
Output is correct |
10 |
Correct |
12 ms |
10232 KB |
Output is correct |
11 |
Correct |
159 ms |
22904 KB |
Output is correct |
12 |
Correct |
182 ms |
24144 KB |
Output is correct |
13 |
Correct |
233 ms |
26104 KB |
Output is correct |
14 |
Correct |
285 ms |
30596 KB |
Output is correct |
15 |
Correct |
288 ms |
32476 KB |
Output is correct |
16 |
Correct |
361 ms |
41464 KB |
Output is correct |
17 |
Correct |
334 ms |
42736 KB |
Output is correct |
18 |
Correct |
456 ms |
41464 KB |
Output is correct |
19 |
Correct |
336 ms |
44024 KB |
Output is correct |
20 |
Correct |
181 ms |
24056 KB |
Output is correct |
21 |
Correct |
147 ms |
23676 KB |
Output is correct |
22 |
Correct |
411 ms |
43888 KB |
Output is correct |
23 |
Correct |
404 ms |
42360 KB |
Output is correct |
24 |
Correct |
436 ms |
42780 KB |
Output is correct |
25 |
Correct |
413 ms |
46840 KB |
Output is correct |
26 |
Correct |
418 ms |
43592 KB |
Output is correct |
27 |
Correct |
405 ms |
42488 KB |
Output is correct |
28 |
Correct |
82 ms |
14772 KB |
Output is correct |
29 |
Correct |
214 ms |
24796 KB |
Output is correct |
30 |
Correct |
204 ms |
24952 KB |
Output is correct |
31 |
Correct |
223 ms |
25128 KB |
Output is correct |
32 |
Correct |
246 ms |
30540 KB |
Output is correct |