9759 | 2024-03-06 13:49:57 | FulopMate | Emezen Rt. | cpp17 | Wrong answer 18/100 | 1.074s | 62272 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);
for (int it = 0; it < 100; 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 | 6ms | 11264 KiB | ||||
subtask2 | 0/16 | ||||||
2 | Accepted | 6ms | 11648 KiB | ||||
3 | Accepted | 6ms | 11620 KiB | ||||
4 | Accepted | 4ms | 11628 KiB | ||||
5 | Accepted | 7ms | 11756 KiB | ||||
6 | Accepted | 6ms | 11888 KiB | ||||
7 | Accepted | 7ms | 12116 KiB | ||||
8 | Accepted | 7ms | 12320 KiB | ||||
9 | Accepted | 7ms | 12492 KiB | ||||
10 | Accepted | 7ms | 12700 KiB | ||||
11 | Wrong answer | 6ms | 12912 KiB | ||||
12 | Accepted | 6ms | 13164 KiB | ||||
13 | Accepted | 6ms | 13244 KiB | ||||
14 | Wrong answer | 6ms | 13332 KiB | ||||
15 | Accepted | 7ms | 13588 KiB | ||||
16 | Wrong answer | 6ms | 13708 KiB | ||||
subtask3 | 18/18 | ||||||
17 | Accepted | 112ms | 34560 KiB | ||||
18 | Accepted | 250ms | 56676 KiB | ||||
19 | Accepted | 263ms | 55596 KiB | ||||
20 | Accepted | 35ms | 16620 KiB | ||||
21 | Accepted | 273ms | 42324 KiB | ||||
22 | Accepted | 363ms | 52912 KiB | ||||
23 | Accepted | 425ms | 59016 KiB | ||||
24 | Accepted | 469ms | 60196 KiB | ||||
25 | Accepted | 532ms | 62272 KiB | ||||
26 | Accepted | 541ms | 62212 KiB | ||||
subtask4 | 0/66 | ||||||
27 | Accepted | 45ms | 17772 KiB | ||||
28 | Accepted | 101ms | 23088 KiB | ||||
29 | Accepted | 195ms | 31328 KiB | ||||
30 | Accepted | 423ms | 52664 KiB | ||||
31 | Accepted | 686ms | 61984 KiB | ||||
32 | Accepted | 555ms | 61988 KiB | ||||
33 | Accepted | 523ms | 61060 KiB | ||||
34 | Accepted | 500ms | 60104 KiB | ||||
35 | Accepted | 261ms | 56164 KiB | ||||
36 | Accepted | 254ms | 56116 KiB | ||||
37 | Accepted | 7ms | 14532 KiB | ||||
38 | Accepted | 16ms | 16396 KiB | ||||
39 | Accepted | 35ms | 20192 KiB | ||||
40 | Accepted | 7ms | 14532 KiB | ||||
41 | Accepted | 8ms | 14784 KiB | ||||
42 | Time limit exceeded | 1.06s | 8752 KiB | ||||
43 | Time limit exceeded | 1.074s | 8780 KiB | ||||
44 | Wrong answer | 449ms | 14252 KiB | ||||
45 | Wrong answer | 17ms | 14204 KiB |