#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cmin(a, b) a=min(a, b)
#define cmax(a, b) a=max(a, b)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
void solve();
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
solve();
return 0;
}
vector<vector<int>> vec;
void print() {
cout << sz(vec) << endl;
for (auto &a: vec) {
for (auto &u: a) cout << u << ' ';
cout << endl;
}
cout << endl;
}
void add(vector<int> &a) { vec.pb(a); }
int n, m;
vector<int> a;
vector<vector<int>> adj;
vector<bool> visited;
vector<int> sz;
void execute(int x, int par=-1) {
for (auto u: adj[x]) if (u!=par && !visited[u]) {
auto temp=a; temp[x]=0, temp[u]=0;
add(temp);
execute(u, x);
add(temp);
}
}
int dfsinit(int x, int par=-1) {
sz[x]=1;
for (auto u: adj[x]) if (!visited[u] && u!=par) sz[x]+=dfsinit(u, x);
return sz[x];
}
int get_centroid(int x, int obj, int par=-1) {
for (auto u: adj[x]) if (!visited[u] && u!=par && sz[u]>=obj) return get_centroid(u, obj, x);
return x;
}
void decompose(int x) {
dfsinit(x);
int centroid=get_centroid(x, sz[x]/2);
execute(centroid);
visited[centroid]=1;
for (auto u: adj[centroid]) if (!visited[u]) decompose(u);
}
void solve() {
cin >> n >> m; a.clear(), a.resize(n, 0); iota(all(a), 1);
adj.clear(), adj.resize(n);
sz.clear(), sz.resize(n), visited.clear(), visited.resize(n);
for (int i=0; i<m; i++) {
int u, v; cin >> u >> v;
adj[u].pb(v), adj[v].pb(u);
}
decompose(0);
print();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
If people start at 1 and 2, then they can avoid each other |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Runtime error |
937 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
If people start at 0 and 3, then they can avoid each other |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
If people start at 1 and 2, then they can avoid each other |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
If people start at 1 and 2, then they can avoid each other |
4 |
Halted |
0 ms |
0 KB |
- |