#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
// #define fisier 1
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double dancila = 3.14159265359; // PI
const double eps = 1e-9;
int n, m, lvl[100002], low[100002], viz[100002];
vector<pair<int, int> > v[100002], v2[100002];
pair<int, int> E[100002];
int ans[100002];
void dfs(int dad, int nod)
{
viz[nod] = 1;
low[nod] = lvl[nod];
for(auto vecin : v[nod])
{
if(vecin.se == dad)
continue;
if(viz[vecin.fi])
{
low[nod] = min(low[nod], lvl[vecin.fi]);
ans[vecin.se] = 1;
continue;
}
lvl[vecin.fi] = lvl[nod] + 1;
dfs(vecin.se, vecin.fi);
if(low[vecin.fi] <= lvl[nod])
ans[vecin.se] = 1;
low[nod] = min(low[nod], low[vecin.fi]);
}
}
int bcc[100002], bcnt;
void dfs2(int nod, int col)
{
bcc[nod] = col;
for(auto vecin : v[nod])
{
if(bcc[vecin.fi])
continue;
if(ans[vecin.se])
dfs2(vecin.fi, col);
else
{
++bcnt;
v2[col].push_back({bcnt, vecin.se});
dfs2(vecin.fi, bcnt);
}
}
}
int dp[100002];
void dfs3(int nod)
{
for(auto vecin : v2[nod])
{
dfs3(vecin.fi);
if(dp[vecin.fi]>0)
{
int u=E[vecin.se].fi;
if(bcc[u]==vecin.fi)
ans[vecin.se]=2;
else
ans[vecin.se]=3;
}
else
if(dp[vecin.fi]<0)
{
int u=E[vecin.se].fi;
if(bcc[u]==vecin.fi)
ans[vecin.se]=3;
else
ans[vecin.se]=2;
}
else
ans[vecin.se]=1;
dp[nod]+=dp[vecin.fi];
}
}
int main()
{
#ifdef fisier
ifstream f("input.in");
ofstream g("output.out");
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= m; ++i)
{
int a, b;
cin >> a >> b;
E[i] = {a, b};
v[a].pb({b, i});
v[b].pb({a, i});
}
vector<int> rad;
for(int i = 1; i <= n; ++i)
if(!viz[i])
{
lvl[i] = 1;
dfs(0, i);
++bcnt;
rad.pb(bcnt);
dfs2(i, bcnt);
}
int p;
cin >> p;
for(; p; --p)
{
int a, b;
cin >> a >> b;
if(bcc[a] == bcc[b])
continue;
++dp[bcc[a]];
--dp[bcc[b]];
}
for(auto it : rad)
dfs3(it);
char ch[5] = "XBRL";
for(int i = 1; i <= m; ++i)
cout << ch[ans[i]];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
8 ms |
5248 KB |
Output is correct |
5 |
Correct |
8 ms |
5248 KB |
Output is correct |
6 |
Correct |
7 ms |
5120 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
8 ms |
5248 KB |
Output is correct |
9 |
Correct |
8 ms |
5120 KB |
Output is correct |
10 |
Correct |
8 ms |
5120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
8 ms |
5248 KB |
Output is correct |
5 |
Correct |
8 ms |
5248 KB |
Output is correct |
6 |
Correct |
7 ms |
5120 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
8 ms |
5248 KB |
Output is correct |
9 |
Correct |
8 ms |
5120 KB |
Output is correct |
10 |
Correct |
8 ms |
5120 KB |
Output is correct |
11 |
Correct |
51 ms |
11128 KB |
Output is correct |
12 |
Correct |
63 ms |
11768 KB |
Output is correct |
13 |
Correct |
61 ms |
12792 KB |
Output is correct |
14 |
Correct |
87 ms |
13816 KB |
Output is correct |
15 |
Correct |
78 ms |
14084 KB |
Output is correct |
16 |
Correct |
77 ms |
15096 KB |
Output is correct |
17 |
Correct |
72 ms |
16504 KB |
Output is correct |
18 |
Correct |
94 ms |
15072 KB |
Output is correct |
19 |
Correct |
72 ms |
17272 KB |
Output is correct |
20 |
Correct |
56 ms |
11768 KB |
Output is correct |
21 |
Correct |
54 ms |
11512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
8 ms |
5248 KB |
Output is correct |
5 |
Correct |
8 ms |
5248 KB |
Output is correct |
6 |
Correct |
7 ms |
5120 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
8 ms |
5248 KB |
Output is correct |
9 |
Correct |
8 ms |
5120 KB |
Output is correct |
10 |
Correct |
8 ms |
5120 KB |
Output is correct |
11 |
Correct |
51 ms |
11128 KB |
Output is correct |
12 |
Correct |
63 ms |
11768 KB |
Output is correct |
13 |
Correct |
61 ms |
12792 KB |
Output is correct |
14 |
Correct |
87 ms |
13816 KB |
Output is correct |
15 |
Correct |
78 ms |
14084 KB |
Output is correct |
16 |
Correct |
77 ms |
15096 KB |
Output is correct |
17 |
Correct |
72 ms |
16504 KB |
Output is correct |
18 |
Correct |
94 ms |
15072 KB |
Output is correct |
19 |
Correct |
72 ms |
17272 KB |
Output is correct |
20 |
Correct |
56 ms |
11768 KB |
Output is correct |
21 |
Correct |
54 ms |
11512 KB |
Output is correct |
22 |
Correct |
94 ms |
17528 KB |
Output is correct |
23 |
Correct |
102 ms |
16436 KB |
Output is correct |
24 |
Correct |
106 ms |
16248 KB |
Output is correct |
25 |
Correct |
111 ms |
19964 KB |
Output is correct |
26 |
Correct |
117 ms |
17400 KB |
Output is correct |
27 |
Correct |
129 ms |
16376 KB |
Output is correct |
28 |
Correct |
41 ms |
9588 KB |
Output is correct |
29 |
Correct |
80 ms |
12664 KB |
Output is correct |
30 |
Correct |
100 ms |
12676 KB |
Output is correct |
31 |
Correct |
83 ms |
12920 KB |
Output is correct |
32 |
Correct |
83 ms |
15480 KB |
Output is correct |