Submission #44580627
Source Code Expand
#include "bits/stdc++.h"
using namespace std;
int nEdge = 1;
struct edge {
int x, y, id;
char color;
friend istream & operator >> (istream &in, edge &A) {
in >> A.x >> A.y >> A.color;
A.id = nEdge++;
return in;
}
};
const int NM = 2e5 + 5;
int n, m, par[NM], sz[NM];
edge e[NM];
char s[NM];
vector<edge> t[3];
vector<int> ans;
bool ok[NM];
void init() {
for (int i = 1; i <= n; ++i) {
par[i] = i;
sz[i] = 1;
}
}
int find_set(int u) {
return par[u] == u ? u : par[u] = find_set(par[u]);
}
bool union_set(int u, int v) {
u = find_set(u);
v = find_set(v);
if (u == v) return false;
if (sz[u] < sz[v]) swap(u, v);
par[v] = u;
sz[u] += sz[v];
return true;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; ++i) cin >> e[i];
for (int i = 1; i <= n; ++i) cin >> s[i];
for (int i = 1; i <= m; ++i) t[(s[e[i].x] != e[i].color) + (s[e[i].y] != e[i].color)].push_back(e[i]);
init();
for (edge &i: t[0]) if (union_set(i.x, i.y)) {
ok[i.x] = ok[i.y] = 1;
ans.push_back(i.id);
}
for (edge &i: t[1]) {
if (s[i.y] == i.color) swap(i.x, i.y);
if (ok[i.x]) continue;
if (union_set(i.x, i.y)) {
ok[i.x] = 1;
ans.push_back(i.id);
}
}
bool check = 1;
for (int i = 1; i <= n; ++i) check &= ok[i];
if (!check) {
cout << "No";
return 0;
}
for (int i = 1; i <= m; ++i) if (union_set(e[i].x, e[i].y)) ans.push_back(i);
cout << "Yes\n";
for (int &i: ans) cout << i << " ";
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Red and Blue Spanning Tree |
| User | cheatkhitacontre |
| Language | C++ 20 (gcc 12.2) |
| Score | 0 |
| Code Size | 1720 Byte |
| Status | WA |
| Exec Time | 47 ms |
| Memory | 13296 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 600 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 01_small_09.txt, 01_small_10.txt, 01_small_11.txt, 01_small_12.txt, 01_small_13.txt, 01_small_14.txt, 01_small_15.txt, 01_small_16.txt, 01_small_17.txt, 02_dense_00.txt, 02_dense_01.txt, 02_dense_02.txt, 02_dense_03.txt, 02_dense_04.txt, 02_dense_05.txt, 02_dense_06.txt, 02_dense_07.txt, 02_dense_08.txt, 02_dense_09.txt, 02_dense_10.txt, 02_dense_11.txt, 03_rnd_00.txt, 03_rnd_01.txt, 03_rnd_02.txt, 03_rnd_03.txt, 03_rnd_04.txt, 03_rnd_05.txt, 03_rnd_06.txt, 03_rnd_07.txt, 04_same_00.txt, 04_same_01.txt, 04_same_02.txt, 04_same_03.txt, 04_same_04.txt, 04_same_05.txt, 04_same_06.txt, 04_same_07.txt, 05_star_00.txt, 05_star_01.txt, 05_star_02.txt, 05_star_03.txt, 05_star_04.txt, 06_cycle_00.txt, 06_cycle_01.txt, 06_cycle_02.txt, 06_cycle_03.txt, 06_cycle_04.txt, 06_cycle_05.txt, 06_cycle_06.txt, 07_hand_00.txt, 07_hand_01.txt, 07_hand_02.txt, 07_hand_03.txt, 07_hand_04.txt, 07_hand_05.txt, 07_hand_06.txt, 07_hand_07.txt, 07_hand_08.txt, 07_hand_09.txt, 07_hand_10.txt, 07_hand_11.txt, 07_hand_12.txt, 07_hand_13.txt, 07_hand_14.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3444 KiB |
| 00_sample_01.txt | AC | 1 ms | 3384 KiB |
| 00_sample_02.txt | AC | 1 ms | 3456 KiB |
| 00_sample_03.txt | AC | 1 ms | 3448 KiB |
| 01_small_00.txt | AC | 1 ms | 3548 KiB |
| 01_small_01.txt | AC | 1 ms | 3448 KiB |
| 01_small_02.txt | AC | 1 ms | 3548 KiB |
| 01_small_03.txt | AC | 1 ms | 3552 KiB |
| 01_small_04.txt | AC | 1 ms | 3468 KiB |
| 01_small_05.txt | AC | 1 ms | 3448 KiB |
| 01_small_06.txt | AC | 1 ms | 3448 KiB |
| 01_small_07.txt | AC | 1 ms | 3548 KiB |
| 01_small_08.txt | AC | 1 ms | 3452 KiB |
| 01_small_09.txt | AC | 1 ms | 3668 KiB |
| 01_small_10.txt | AC | 1 ms | 3544 KiB |
| 01_small_11.txt | AC | 1 ms | 3544 KiB |
| 01_small_12.txt | AC | 1 ms | 3636 KiB |
| 01_small_13.txt | AC | 1 ms | 3424 KiB |
| 01_small_14.txt | AC | 1 ms | 3636 KiB |
| 01_small_15.txt | AC | 1 ms | 3640 KiB |
| 01_small_16.txt | AC | 1 ms | 3560 KiB |
| 01_small_17.txt | AC | 1 ms | 3560 KiB |
| 02_dense_00.txt | AC | 11 ms | 6156 KiB |
| 02_dense_01.txt | AC | 15 ms | 7676 KiB |
| 02_dense_02.txt | AC | 12 ms | 6364 KiB |
| 02_dense_03.txt | AC | 13 ms | 6632 KiB |
| 02_dense_04.txt | AC | 12 ms | 6512 KiB |
| 02_dense_05.txt | AC | 20 ms | 9228 KiB |
| 02_dense_06.txt | AC | 10 ms | 6416 KiB |
| 02_dense_07.txt | AC | 7 ms | 5056 KiB |
| 02_dense_08.txt | AC | 11 ms | 6060 KiB |
| 02_dense_09.txt | AC | 8 ms | 5376 KiB |
| 02_dense_10.txt | AC | 7 ms | 5328 KiB |
| 02_dense_11.txt | AC | 10 ms | 6048 KiB |
| 03_rnd_00.txt | AC | 30 ms | 11444 KiB |
| 03_rnd_01.txt | AC | 12 ms | 6388 KiB |
| 03_rnd_02.txt | AC | 21 ms | 9384 KiB |
| 03_rnd_03.txt | AC | 39 ms | 12080 KiB |
| 03_rnd_04.txt | AC | 28 ms | 10212 KiB |
| 03_rnd_05.txt | AC | 22 ms | 8692 KiB |
| 03_rnd_06.txt | AC | 26 ms | 9936 KiB |
| 03_rnd_07.txt | AC | 31 ms | 11020 KiB |
| 04_same_00.txt | AC | 32 ms | 10888 KiB |
| 04_same_01.txt | AC | 28 ms | 10904 KiB |
| 04_same_02.txt | AC | 41 ms | 12464 KiB |
| 04_same_03.txt | AC | 21 ms | 8548 KiB |
| 04_same_04.txt | AC | 25 ms | 10676 KiB |
| 04_same_05.txt | AC | 26 ms | 11308 KiB |
| 04_same_06.txt | AC | 20 ms | 9684 KiB |
| 04_same_07.txt | AC | 24 ms | 10660 KiB |
| 05_star_00.txt | AC | 43 ms | 13036 KiB |
| 05_star_01.txt | AC | 40 ms | 13200 KiB |
| 05_star_02.txt | AC | 40 ms | 12976 KiB |
| 05_star_03.txt | AC | 41 ms | 13196 KiB |
| 05_star_04.txt | AC | 39 ms | 13028 KiB |
| 06_cycle_00.txt | AC | 45 ms | 13296 KiB |
| 06_cycle_01.txt | AC | 46 ms | 12948 KiB |
| 06_cycle_02.txt | AC | 46 ms | 13064 KiB |
| 06_cycle_03.txt | AC | 46 ms | 13000 KiB |
| 06_cycle_04.txt | AC | 47 ms | 13040 KiB |
| 06_cycle_05.txt | WA | 29 ms | 11128 KiB |
| 06_cycle_06.txt | WA | 29 ms | 11204 KiB |
| 07_hand_00.txt | AC | 26 ms | 9696 KiB |
| 07_hand_01.txt | AC | 27 ms | 9696 KiB |
| 07_hand_02.txt | AC | 20 ms | 9244 KiB |
| 07_hand_03.txt | AC | 20 ms | 9692 KiB |
| 07_hand_04.txt | AC | 30 ms | 12120 KiB |
| 07_hand_05.txt | AC | 29 ms | 12340 KiB |
| 07_hand_06.txt | AC | 34 ms | 11212 KiB |
| 07_hand_07.txt | AC | 38 ms | 12020 KiB |
| 07_hand_08.txt | AC | 42 ms | 12440 KiB |
| 07_hand_09.txt | AC | 44 ms | 12748 KiB |
| 07_hand_10.txt | AC | 46 ms | 13236 KiB |
| 07_hand_11.txt | AC | 46 ms | 13104 KiB |
| 07_hand_12.txt | AC | 47 ms | 13268 KiB |
| 07_hand_13.txt | AC | 42 ms | 12172 KiB |
| 07_hand_14.txt | AC | 41 ms | 12188 KiB |