# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1048522 |
2024-08-08T08:06:17 Z |
European Bad Bitch(#11090) |
Make them Meet (EGOI24_makethemmeet) |
C++17 |
|
784 ms |
1048580 KB |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<lint, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define cr(v, n) (v).clear(), (v).resize(n);
const int MAXN = 105;
struct disj {
vector<int> pa;
void init(int n) {
pa.clear();
pa.resize(n);
iota(all(pa), 0);
}
int find(int x) { return pa[x] = (pa[x] == x ? x : find(pa[x])); }
bool uni(int p, int q) {
p = find(p);
q = find(q);
if (p == q)
return 0;
pa[q] = p;
return 1;
}
} disj;
int n;
vector<int> gph[MAXN];
vector<vector<int>> seqs;
void swab(int u, int v) {
vector<int> a(n);
iota(all(a), 0);
a[v] = u;
seqs.push_back(a);
}
void dfs(int x, int p) {
for (auto &y : gph[x]) {
swab(x, y);
dfs(y, x);
swab(x, y);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int m;
cin >> n >> m;
disj.init(n);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
if (disj.uni(u, v)) {
gph[u].push_back(v);
gph[v].push_back(u);
}
}
for (int i = 0; i < n; i++)
dfs(i, -1);
cout << sz(seqs) << "\n";
for (auto &v : seqs) {
for (auto &w : v)
cout << w << " ";
cout << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
775 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
761 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
784 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
775 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
775 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |