結果
| 問題 |
No.3056 Disconnected Coloring
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-24 20:21:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 2,000 ms |
| コード長 | 4,251 bytes |
| コンパイル時間 | 1,338 ms |
| コンパイル使用メモリ | 122,048 KB |
| 実行使用メモリ | 18,016 KB |
| 最終ジャッジ日時 | 2025-03-24 20:21:58 |
| 合計ジャッジ時間 | 7,938 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 34 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:72:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
72 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <sstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <ctime>
#include <assert.h>
#include <deque>
#include <list>
#include <stack>
#include <numeric>
#include <iomanip>
using namespace std;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef pair<long long , long long> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef pair<int, long long > pil;
typedef pair<long long, pii> plii;
typedef pair<double, int> pdi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ull, ull> puu;
typedef long double ld;
const int N = 2000086, MOD = 998244353, INF = 0x3f3f3f3f, MID = 333;
const long double EPS = 1e-9;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
// int dx[8] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[8] = {1, 2, 2, 1, -1, -2, -2, -1};
int n, m, cnt;
int w[N];
vector<ll> num;
ll res;
ll lowbit(ll x) { return x & -x; }
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
inline double rand(double l, double r) { return (double)rand() / RAND_MAX * (r - l) + l; }
inline ll qmi(ll a, ll b, ll c) { ll res = 1; while (b) { if (b & 1) res = res * a % c; a = a * a % c; b >>= 1; } return res; }
inline ll qmi(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; }
inline double qmi(double a, ll b) { double res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; }
inline ll C(ll a, ll b, int* c) { if (a < b) return 0; ll res = 1; for (ll j = a, i = 1; i < b + 1; i++, j--) res *= j; for (ll j = a, i = 1; i < b + 1; i++, j--) res /= i; return res; }
inline int find_(int x) { return lower_bound(num.begin(), num.end(), x) - num.begin(); }
int e[N], ne[N], h[N], idx;
void add(int a, int b, int c) { e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++; }
char ans[N];
bool st[N];
int main() {
cin >> n >> m;
int d1 = 0, dn = 0;
memset(h, -1, sizeof(int) * (n + 10));
if (m & 1) {
puts("-1");
return 0;
}
for (int i = 1; i < m + 1; i++) {
int a, b;
scanf("%d%d", &a, &b);
if (a > b) swap(a, b);
if (a == 1 && b == n) {
puts("-1");
return 0;
}
d1 += a == 1, dn += b == n;
add(a, b, i), add(b, a, i);
ans[i] = 'R';
}
if (d1 <= m / 2) {
queue<int> q;
q.push(1);
st[1] = 1;
int c = m >> 1;
while (q.size() && c) {
auto u = q.front(); q.pop();
for (int i = h[u]; ~i && c; i = ne[i]) {
int j = e[i];
if (j == n || ans[w[i]] == 'B') continue;
c--;
ans[w[i]] = 'B';
if (!st[j]) st[j] = 1, q.push(j);
}
}
if (c) {
for (int i = 2; i < n; i++)
if (!st[i]) {
for (int j = h[i]; ~j && c; j = ne[j]) {
if (ans[w[j]] == 'B') continue;
ans[w[j]] = 'B';
c--;
}
}
}
if (c) puts("-1");
else puts(ans + 1);
} else {
queue<int> q;
q.push(n);
st[n] = 1;
int c = m >> 1;
while (q.size() && c) {
auto u = q.front(); q.pop();
for (int i = h[u]; ~i && c; i = ne[i]) {
int j = e[i];
if (j == 1 || ans[w[i]] == 'B') continue;
c--;
ans[w[i]] = 'B';
if (!st[j]) st[j] = 1, q.push(j);
}
}
if (c) {
for (int i = 2; i < n; i++)
if (!st[i]) {
for (int j = h[i]; ~j && c; j = ne[j]) {
if (ans[w[j]] == 'B') continue;
ans[w[j]] = 'B';
c--;
}
}
}
if (c) puts("-1");
else puts(ans + 1);
}
return 0;
}