#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define st first
#define nd second
#define pb push_back
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mxn = 1003;
mt19937 _rand(time(NULL));
clock_t z;
int n, m;
vector<int> g[mxn];
bool adj[mxn][mxn];
int vis[mxn];
bool deleted[mxn];
int uniq = 0;
int aux[mxn];
int parent[mxn];
void expand(int r, int x, int y){
uniq ++;
queue<int> Q;
Q.push(x);
vis[x] = uniq;
vis[r] = uniq;
parent[x] = x;
while(!Q.empty()){
int c = Q.front();
Q.pop();
for(auto e : g[c]){
if(vis[e] == uniq) continue;
vis[e] = uniq;
parent[e] = c;
Q.push(e);
}
}
vector<int> sol;
sol.pb(r);
sol.pb(y);
while(sol.back() != x){
sol.pb(parent[sol.back()]);
}
for(auto u : sol) cout<<u+1<<' ';
cout<<endl;
exit(0);
}
vector<int> check(vector<int> G, int r){
++uniq;
for(auto u : G){
aux[u] = uniq;
}
vector<int> S;
for(auto u : g[r]){
if(deleted[u]) continue;
for(auto e : g[u]){
if(deleted[e]) continue;
if(aux[e] == uniq){
S.pb(u);
break;
}
}
}
fr(i, 0, (int)S.size()){
fr(j, i+1, (int)S.size()){
if(!adj[S[i]][S[j]]){
expand(r, S[i], S[j]);
}
}
}
for(auto u : S) G.pb(u);
return G;
}
vector<vector<int> > generate_next(vector<vector<int> > G, int r){
fr(i, 0, (int)G.size()){
G[i] = check(G[i], r);
}
vector<int> S;
for(auto u : g[r]){
if(deleted[u]) continue;
S.pb(u);
}
G.pb(S);
return G;
}
vector<int> gp;
void dfs(int u){
gp.pb(u);
vis[u] = uniq;
for(auto e : g[u]){
if(aux[e] != uniq || vis[e] == uniq) continue;
dfs(e);
}
}
vector<vector<int> > split(vector<int> v, int r){
++uniq;
for(auto u : v) aux[u] = uniq;
vis[r] = uniq;
for(auto u : g[r]) vis[u] = uniq;
vector<vector<int> > G;
for(auto u : v){
if(vis[u] == uniq) continue;
gp.clear();
dfs(u);
G.pb(gp);
}
return G;
}
void solve(vector<int> v){
if((int)v.size() < 4) return;
int r = v[0];
vector<vector<int> > G = split(v, r);
G = generate_next(G, r);
for(auto Gp : G){
solve(Gp);
}
}
int main(){
cin >> n >> m;
fr(i, 0, m){
int u, v;
cin >> u >> v;
--u, --v;
g[u].pb(v);
g[v].pb(u);
adj[u][v] = true;
adj[v][u] = true;
}
vector<int> v;
fr(i, 0, n) v.pb(i);
solve(v);
cout<<"no"<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
472 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1101 ms |
459988 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1076 ms |
131700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
2220 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1080 ms |
71120 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1124 ms |
900268 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |