9758 | 2024-03-06 13:17:54 | FulopMate | Emezen Rt. | cpp17 | Wrong answer 0/100 | 263ms | 49432 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAX(a, b) (a) = max((a), (b))
#define MIN(a, b) (a) = min((a), (b))
#define all(a) (a).begin(), (a).end()
#define sortedpair(a, b) {min((a), (b)), max((a), (b))}
const ll MOD = 1e9+7;
const int MAXN = 100'001;
struct E {
int u, v, w;
E(int a, int b, int c) : u(a), v(b), w(c) {}
};
int par[MAXN], ans[MAXN];
vector<int> g[MAXN];
int get(int u) {
if (par[u] == u) return u;
return par[u]=get(par[u]);
}
bool unio(int u, int v) {
u = get(u); v=get(v);
if (u == v) return false;
par[u]=v;
return true;
}
void dfs(int u, int p = -1, int d = 0) {
ans[u] = d&1;
for (int v : g[u]) {
if (v != p) dfs(v, u, d+1);
}
}
void solve(){
int n, m; cin>>n>>m;
iota(par, par+n+1, 0);
map<pair<int, int>, int> mp;
vector<pair<int, int>> a;
for (int i = 0; i < m; i++) {
int u, v; cin >> u >> v;
a.emplace_back(u, v);
if (u > v) swap(u, v);
mp[{u, v}]++;
}
for (int i = 1; i <= n; i++) {
g[i].clear();
}
vector<E> edges;
for (auto [e, x] : mp) {
edges.emplace_back(e.first, e.second, x);
}
sort(edges.begin(), edges.end(), [](auto x, auto y){
return x.w > y.w;
});
for (E e : edges) {
if (unio(e.u, e.v)) {
g[e.u].emplace_back(e.v);
g[e.v].emplace_back(e.u);
}
}
dfs(1);
int ok = 0;
for (auto [u, v] : a) {
if (ans[u] == ans[v]) ok++;
}
if (ok > m/2) {
cout << "-1\n";
return;
}
int cnt = count(ans+1, ans+n+1, 1);
cout << cnt << "\n";
for (int i = 1; i <= n; i++) {
if (ans[i]) cout << i << " ";
}
cout << "\n";
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int _t = 1;
cin >> _t;
while (_t--) {
solve();
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 4ms | 6608 KiB | ||||
subtask2 | 0/16 | ||||||
2 | Wrong answer | 4ms | 6904 KiB | ||||
3 | Accepted | 4ms | 7216 KiB | ||||
4 | Accepted | 4ms | 7508 KiB | ||||
5 | Accepted | 4ms | 7732 KiB | ||||
6 | Accepted | 4ms | 7680 KiB | ||||
7 | Wrong answer | 4ms | 7512 KiB | ||||
8 | Wrong answer | 4ms | 7688 KiB | ||||
9 | Accepted | 4ms | 7768 KiB | ||||
10 | Wrong answer | 4ms | 7608 KiB | ||||
11 | Wrong answer | 4ms | 7868 KiB | ||||
12 | Accepted | 4ms | 7960 KiB | ||||
13 | Accepted | 4ms | 8028 KiB | ||||
14 | Accepted | 4ms | 7968 KiB | ||||
15 | Accepted | 4ms | 8232 KiB | ||||
16 | Accepted | 4ms | 8284 KiB | ||||
subtask3 | 0/18 | ||||||
17 | Accepted | 79ms | 26684 KiB | ||||
18 | Accepted | 186ms | 45512 KiB | ||||
19 | Accepted | 186ms | 45516 KiB | ||||
20 | Wrong answer | 8ms | 10292 KiB | ||||
21 | Accepted | 100ms | 31084 KiB | ||||
22 | Accepted | 150ms | 40164 KiB | ||||
23 | Accepted | 209ms | 45744 KiB | ||||
24 | Accepted | 246ms | 47376 KiB | ||||
25 | Accepted | 225ms | 48992 KiB | ||||
26 | Accepted | 263ms | 49056 KiB | ||||
subtask4 | 0/66 | ||||||
27 | Wrong answer | 8ms | 10724 KiB | ||||
28 | Wrong answer | 21ms | 14572 KiB | ||||
29 | Accepted | 54ms | 21984 KiB | ||||
30 | Accepted | 175ms | 40636 KiB | ||||
31 | Accepted | 232ms | 49212 KiB | ||||
32 | Accepted | 231ms | 49432 KiB | ||||
33 | Accepted | 226ms | 48792 KiB | ||||
34 | Accepted | 225ms | 47856 KiB | ||||
35 | Wrong answer | 190ms | 46124 KiB | ||||
36 | Wrong answer | 189ms | 46124 KiB | ||||
37 | Wrong answer | 6ms | 9476 KiB | ||||
38 | Accepted | 10ms | 11052 KiB | ||||
39 | Wrong answer | 24ms | 14332 KiB | ||||
40 | Accepted | 4ms | 9568 KiB | ||||
41 | Wrong answer | 6ms | 9924 KiB | ||||
42 | Accepted | 57ms | 9216 KiB | ||||
43 | Wrong answer | 24ms | 9224 KiB | ||||
44 | Wrong answer | 7ms | 9248 KiB | ||||
45 | Wrong answer | 4ms | 9256 KiB |