# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1098159 | Trisanu_Das | Make them Meet (EGOI24_makethemmeet) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, m, sink, root;
vector<int> adj[105];
void dfs(int u, int p, int dep){
for(int v : adj[u]){
if(v == p) continue;
if(dep & 1) odd[v] = u;
else even[v] = u;
dfs(v, u, dep + 1);
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
while(m--){
int u, v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 0; i < n; i++){
if(adj[i].size() == 1){
sink = i;
root = adj[i][0];
break;
}
}
int odd[n], even[n];
iota(odd, odd + n, 0);
iota(even, even + n, 0);
odd[sink] = root;
dfs(root, -1, 0);
cout << 2 * n << '\n';
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++) cout << even[j] << ' ';
cout << '\n';
for(int j = 0; j < n; j++) cout << odd[j] << ' ';
cout << '\n';
}
}