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;
vector<vector<int>> graph;
int n, m;
vector<int> c;
vector<bool> visited;
void pathlike(){
cout << "600\n";
for(int i = 0; i < 600; i++){
for(int j = 0; j < n; j++){
cout << (j+(i%2))/2 << ' ';
}
cout << '\n';
}
}
void dfs(int v, int p, int d){
visited[v]=1;
if(d%2) c[v] = p;
else c[v] = v;
for(auto i : graph[v]){
if(!visited[i]) dfs(i, v, d+1);
}
}
int main(){
cin >> n >> m;
graph.resize(n);
c.resize(n);
visited.resize(n);
for(int i = 0; i < m; i++){
int x, y;
cin >> x >> y;
graph[x].push_back(y);
graph[y].push_back(x);
}
if(m==(n*(n-1))/2){
pathlike();
return 0;
}
int root = 0;
for(int i = 0; i < n; i++) if(graph[i].size() == 1) root = i;
cout << "600\n";
for(int i = 0; i < 600; i++){
fill(visited.begin(), visited.end(), 0);
dfs(root, -1, i%2);
c[root] = graph[root][0];
c[graph[root][0]]=graph[root][0];
for(auto i : c){
cout << i << ' ';
}
cout << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |