結果
| 問題 |
No.3056 Disconnected Coloring
|
| コンテスト | |
| ユーザー |
Iroha_3856
|
| 提出日時 | 2025-03-14 21:45:28 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,210 bytes |
| コンパイル時間 | 4,227 ms |
| コンパイル使用メモリ | 287,884 KB |
| 実行使用メモリ | 17,952 KB |
| 最終ジャッジ日時 | 2025-03-14 21:46:03 |
| 合計ジャッジ時間 | 19,780 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 RE * 1 |
| other | AC * 10 RE * 24 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:64:14: warning: ‘R’ may be used uninitialized [-Wmaybe-uninitialized]
64 | R++;
| ~^~
main.cpp:56:9: note: ‘R’ was declared here
56 | int R, B;
| ^
main.cpp:75:14: warning: ‘B’ may be used uninitialized [-Wmaybe-uninitialized]
75 | B++;
| ~^~
main.cpp:56:12: note: ‘B’ was declared here
56 | int R, B;
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = (int)(l); i<(int)(r); i++)
#define ll long long
int main() {
int N, M; cin >> N >> M;
if (M%2) {
cout << -1 << endl;
return 0;
}
vector<vector<pair<int, int>>> G(N);
vector<int> unuse;
rep(i, 0, M) {
int u, v; cin >> u >> v;
u--; v--;
if (u == 0 and v == N-1) {
cout << -1 << endl;
return 0;
}
if (u != 0 and u != N-1 and v != 0 and v != N-1) {
unuse.push_back(i);
}
G[u].push_back({v, i});
G[v].push_back({u, i});
}
// cout << "ok1" << endl;
auto reachable = [&](int v) -> vector<bool> {
int x = N - 1 - v;
vector<bool> ret(N, false);
queue<int> Q;
ret[v] = true;
Q.push(v);
while(!Q.empty()) {
int u = Q.front(); Q.pop();
// cout << u << " ";
for (auto[to, id] : G[u]) {
if (to == x) continue;
if (!ret[to]) {
ret[to] = true;
Q.push(to);
}
}
}
// cout << endl;
assert(ret[x] == false);
return ret;
};
vector<bool> R1 = reachable(0), RN = reachable(N-1);
// for (auto v : R1) cout << v << " ";
// cout << endl;
// for (auto v : RN) cout << v << " ";
// cout << endl;
string ans(M, '.');
int R, B;
for (auto[to, id] : G[0]) {
if (!R1[to] or !RN[to]) {
//いらない
unuse.push_back(id);
}
else {
ans[id] = 'R';
R++;
}
}
// cout << "ok" << endl;
for (auto[to, id] : G[N-1]) {
if (!R1[to] or !RN[to]) {
//いらない
unuse.push_back(id);
}
else {
ans[id] = 'B';
B++;
}
}
// cout << "ok3" << endl;
// cout << ans << endl;
assert(R <= M/2);
assert(B <= M/2);
while(R < M/2) {
int t = unuse.back(); unuse.pop_back();
ans[t] = 'R';
R++;
}
for (auto t : unuse) ans[t] = 'B';
cout << ans << endl;
}
Iroha_3856