9764 | 2024-03-06 13:54:00 | FulopMate | Emezen Rt. | cpp17 | Wrong answer 0/100 | 1.052s | 60600 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], g2[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;
g2[u].emplace_back(v);
g2[v].emplace_back(u);
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 x = 0;
for (int it = 0; it < sqrt(n); it++) {
for (int i = 1; i <= n; i++) {
int cnt = 0;
for (int u : g2[i]) {
cnt += (ans[u]==ans[i]);
}
if (cnt > g2[i].size()/2) {
ans[i] ^= 1;
}
}
}
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 | 7ms | 11260 KiB | ||||
subtask2 | 0/16 | ||||||
2 | Accepted | 6ms | 11512 KiB | ||||
3 | Accepted | 6ms | 11668 KiB | ||||
4 | Accepted | 7ms | 11888 KiB | ||||
5 | Accepted | 7ms | 12096 KiB | ||||
6 | Accepted | 7ms | 12316 KiB | ||||
7 | Accepted | 7ms | 12528 KiB | ||||
8 | Accepted | 6ms | 12608 KiB | ||||
9 | Accepted | 6ms | 12848 KiB | ||||
10 | Accepted | 6ms | 13056 KiB | ||||
11 | Wrong answer | 7ms | 13068 KiB | ||||
12 | Accepted | 7ms | 13064 KiB | ||||
13 | Accepted | 6ms | 13172 KiB | ||||
14 | Wrong answer | 6ms | 13172 KiB | ||||
15 | Accepted | 6ms | 13044 KiB | ||||
16 | Wrong answer | 6ms | 13044 KiB | ||||
subtask3 | 0/18 | ||||||
17 | Accepted | 98ms | 33700 KiB | ||||
18 | Accepted | 256ms | 55912 KiB | ||||
19 | Accepted | 261ms | 54552 KiB | ||||
20 | Accepted | 83ms | 15692 KiB | ||||
21 | Accepted | 657ms | 41092 KiB | ||||
22 | Accepted | 871ms | 52040 KiB | ||||
23 | Accepted | 708ms | 58092 KiB | ||||
24 | Accepted | 833ms | 59200 KiB | ||||
25 | Time limit exceeded | 1.016s | 31852 KiB | ||||
26 | Time limit exceeded | 1.036s | 31980 KiB | ||||
subtask4 | 0/66 | ||||||
27 | Accepted | 115ms | 17108 KiB | ||||
28 | Accepted | 256ms | 22288 KiB | ||||
29 | Accepted | 453ms | 30456 KiB | ||||
30 | Time limit exceeded | 1.019s | 51920 KiB | ||||
31 | Time limit exceeded | 1.052s | 32072 KiB | ||||
32 | Time limit exceeded | 1.049s | 32164 KiB | ||||
33 | Accepted | 999ms | 60600 KiB | ||||
34 | Time limit exceeded | 1.049s | 31220 KiB | ||||
35 | Accepted | 263ms | 55680 KiB | ||||
36 | Accepted | 252ms | 55560 KiB | ||||
37 | Accepted | 8ms | 14236 KiB | ||||
38 | Accepted | 14ms | 16056 KiB | ||||
39 | Accepted | 32ms | 19912 KiB | ||||
40 | Accepted | 8ms | 14248 KiB | ||||
41 | Accepted | 8ms | 14544 KiB | ||||
42 | Time limit exceeded | 1.042s | 9248 KiB | ||||
43 | Time limit exceeded | 1.039s | 8884 KiB | ||||
44 | Wrong answer | 46ms | 13976 KiB | ||||
45 | Wrong answer | 9ms | 13952 KiB |