結果
| 問題 |
No.3056 Disconnected Coloring
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-14 22:28:57 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,812 bytes |
| コンパイル時間 | 7,136 ms |
| コンパイル使用メモリ | 333,180 KB |
| 実行使用メモリ | 17,152 KB |
| 最終ジャッジ日時 | 2025-03-14 22:29:14 |
| 合計ジャッジ時間 | 15,348 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 13 WA * 21 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
const ll MOD = 998244353;
const double INFD = 1.0E18;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
//const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//const int dx[8] = {2, 1, -1, -2, -2, -1, 1, 2};
//const int dy[8] = {1, 2, 2, 1, -1, -2, -2, -1};
using Pair = pair<ll, ll>;
using Graph = vector<vector<pair<int, int>>>;
using mint = atcoder::modint998244353;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int n, m; cin >> n >> m;
Graph G(n);
bool ok = true;
for (int i = 0; i < m; i++){
int u, v; cin >> u >> v; u--; v--;
if (u == 0 && v == n - 1) ok = false;
G[u].push_back({v, i});
G[v].push_back({u, i});
}
if (m % 2 == 1 || ok == false){
cout << -1 << endl;
return 0;
}
atcoder::dsu uf(n);
vector<char> ans(m, '-');
int x = 0;
if (G[0].size() > m / 2) x = n - 1;
assert(G[x].size() <= m / 2);
for (auto [v, idx] : G[x]){
ans[idx] = 'R';
uf.merge(x, v);
}
int rem = m / 2 - G[x].size();
//逆側からBFS
queue<int> q; q.push(n - 1 - x);
while (!q.empty()){
int v = q.front(); q.pop();
for (auto [nv, idx] : G[v]){
if (uf.same(nv, x)) continue;
ans[idx] = 'R';
rem--;
if (rem > 0) q.push(nv);
}
}
for (int i = 0; i < m; i++){
if (ans[i] != '-') continue;
ans[i] = (rem > 0 ? 'R' : 'B');
}
for (int i = 0; i < m; i++) cout << ans[i];
cout << endl;
return 0;
}