-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEulerTour.cpp
More file actions
71 lines (57 loc) · 1.17 KB
/
EulerTour.cpp
File metadata and controls
71 lines (57 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//http://codeforces.com/contest/780/problem/E
//the order of vertices visited by a DFS, where each vertex v is written down every time DFS visits it (in particular, when a recursive call made from v terminates)
//Note that the Euler tour has exactly 2n - 1
#include<iostream>
#include<vector>
#include<list>
#include<map>
using namespace std;
const int NN=2e5+5;
vector<int> ajdList[NN];
vector<int> euler;
int visited[NN];
void eulerPath(int&index,int node){
euler.push_back(node+1);
visited[node]=1;
for(auto neighbour:ajdList[node]){
if(!visited[neighbour]){
eulerPath(index,neighbour);
euler.push_back(node+1);
}
}
}
int main(){
int n,m,k;
cin>>n>>m>>k;
for(int i=0;i<m;i++){
int x,y;
cin>>x>>y;
x=x-1;
y=y-1;
ajdList[x].push_back(y);
ajdList[y].push_back(x);
}
for(int i=0;i<n;i++){
visited[i]=0;
}
int ind=0;
int node=0;
eulerPath(ind,node);
int mm=(2*n+k-1)/k;
int index=0;
int x=euler.size();
for(int i=0;i<k;i++){
if(index!=x){
int temp=min(mm,x-index);
printf("%d ",temp);
for(int j=0;j<temp;j++){
printf("%d ",euler[index++]);
}
printf("\n");
}
else{
cout<<"1 1"<<endl;
}
}
return 0;
}