/// In The Name Of God
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define nl '\n'
#define ioi exit(0);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = (int)3e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
int n, m, k;
int v[N], u[N], x[N], y[N];
multiset <int> g[N];
int tmr;
int was[N], ans[N];
bool check() {
for (int i = 1; i <= k; i++) {
++tmr;
was[x[i]] = tmr;
bool ok = 0;
queue <int> q;
q.push(x[i]);
while (sz(q)) {
int v = q.front();
if (v == y[i]) {
ok = 1;
break;
}
q.pop();
for (auto to : g[v]) {
if (was[to] != tmr) {
was[to] = tmr;
q.push(to);
}
}
}
if (!ok) return 0;
}
return 1;
}
int main() {
#ifdef IOI2018
freopen ("in.txt", "r", stdin);
#endif
Kazakhstan
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> v[i] >> u[i];
g[v[i]].insert(u[i]);
g[u[i]].insert(v[i]);
}
cin >> k;
for (int i = 1; i <= k; i++) {
cin >> x[i] >> y[i];
}
for (int i = 1; i <= m; i++) {
g[u[i]].erase(g[u[i]].find(v[i]));
if (check()) ans[i] = 1;
g[u[i]].insert(v[i]);
g[v[i]].erase(g[v[i]].find(u[i]));
if (check()) {
if (ans[i] == 1) ans[i] = 3;
else ans[i] = 2;
}
g[v[i]].insert(u[i]);
if (ans[i] == 1) g[u[i]].erase(g[u[i]].find(v[i]));
else if (ans[i] == 2) g[v[i]].erase(g[v[i]].find(u[i]));
}
for (int i = 1; i <= m; i++) {
if (ans[i] == 3) cout << 'B';
else if (ans[i] == 1) cout << 'R';
else cout << 'L';
}
ioi
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14456 KB |
Output is correct |
2 |
Correct |
13 ms |
14576 KB |
Output is correct |
3 |
Correct |
316 ms |
14912 KB |
Output is correct |
4 |
Correct |
121 ms |
15000 KB |
Output is correct |
5 |
Correct |
2248 ms |
15100 KB |
Output is correct |
6 |
Correct |
39 ms |
15100 KB |
Output is correct |
7 |
Correct |
2029 ms |
15100 KB |
Output is correct |
8 |
Correct |
1100 ms |
15104 KB |
Output is correct |
9 |
Correct |
2455 ms |
15132 KB |
Output is correct |
10 |
Correct |
1301 ms |
15192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14456 KB |
Output is correct |
2 |
Correct |
13 ms |
14576 KB |
Output is correct |
3 |
Correct |
316 ms |
14912 KB |
Output is correct |
4 |
Correct |
121 ms |
15000 KB |
Output is correct |
5 |
Correct |
2248 ms |
15100 KB |
Output is correct |
6 |
Correct |
39 ms |
15100 KB |
Output is correct |
7 |
Correct |
2029 ms |
15100 KB |
Output is correct |
8 |
Correct |
1100 ms |
15104 KB |
Output is correct |
9 |
Correct |
2455 ms |
15132 KB |
Output is correct |
10 |
Correct |
1301 ms |
15192 KB |
Output is correct |
11 |
Execution timed out |
3029 ms |
26456 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14456 KB |
Output is correct |
2 |
Correct |
13 ms |
14576 KB |
Output is correct |
3 |
Correct |
316 ms |
14912 KB |
Output is correct |
4 |
Correct |
121 ms |
15000 KB |
Output is correct |
5 |
Correct |
2248 ms |
15100 KB |
Output is correct |
6 |
Correct |
39 ms |
15100 KB |
Output is correct |
7 |
Correct |
2029 ms |
15100 KB |
Output is correct |
8 |
Correct |
1100 ms |
15104 KB |
Output is correct |
9 |
Correct |
2455 ms |
15132 KB |
Output is correct |
10 |
Correct |
1301 ms |
15192 KB |
Output is correct |
11 |
Execution timed out |
3029 ms |
26456 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |