#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<set<int>> adj;
vector<bool> visited, visited2, ok, tovisit;
bool dfs(int x) {
bool flag=0;
if (ok[x]) flag=1;
visited2[x]=1;
for (auto u: adj[x]) if (!visited[u] && !visited2[u]) {
flag|=dfs(u);
}
return tovisit[x]=flag;
}
void execute(int x) {
visited[x]=1;
visited2.clear(), visited2.resize(n, 0);
tovisit.clear(), tovisit.resize(n, 0);
dfs(x);
for (auto u: adj[x]) if (!visited[u] && tovisit[u]) {
auto temp=a; temp[x]=0, temp[u]=0;
add(temp);
execute(u);
add(temp);
}
}
void solve() {
cin >> n >> m; a.clear(), a.resize(n, 0); iota(all(a), 1);
adj.clear(), adj.resize(n), ok.clear(), ok.resize(n, 1);
vector<set<int>> adjbase;
for (int i=0; i<m; i++) {
int u, v; cin >> u >> v;
adj[u].insert(v), adj[v].insert(u);
}
adjbase=adj;
for (int i=0; i<n-1; i++) {
int best=-1;
for (int j=0; j<n; j++) if ((best==-1 && ok[j]) || (sz(adjbase[j])!=0 && sz(adjbase[best])<sz(adjbase[j]))) {
best=j;
}
visited.clear(), visited.resize(n, 0);
execute(best);
ok[best]=0;
for (auto u: adjbase[best]) {
adjbase[u].erase(best);
}
adjbase[best].clear();
}
print();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
If people start at 0 and 2, then they can avoid each other |
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 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
508 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Partially correct |
9 ms |
1104 KB |
Partially correct |
7 |
Partially correct |
21 ms |
1760 KB |
Partially correct |
8 |
Partially correct |
41 ms |
3156 KB |
Partially correct |
9 |
Partially correct |
688 ms |
22716 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
If people start at 1 and 2, then they can avoid each other |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
If people start at 0 and 2, then they can avoid each other |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
If people start at 0 and 2, then they can avoid each other |
3 |
Halted |
0 ms |
0 KB |
- |