-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathe.cpp
72 lines (67 loc) · 1.49 KB
/
e.cpp
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
72
#include <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
int N, M, Q;
vector<int> graph[300000], tg[300000];
int a[300000], b[300000], oc[300000];
bool vis[300000];
int d[300000];
void dfs(int id){
for(int i : graph[id]){
if(vis[i]) continue;
vis[i] = true;
tg[id].push_back(i), tg[i].push_back(id);
dfs(i);
}
}
void dfsd(int id, int par, int di){
d[id] = di;
for(int i : tg[id]){
if(i == par) continue;
dfsd(i, id, di+1);
}
}
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> N >> M;
for(int i = 0; i < M; i++){
int u, v; eat >> u >> v;
graph[u-1].push_back(v-1);
graph[v-1].push_back(u-1);
}
eat >> Q;
for(int i = 0; i < Q; i++){
eat >> a[i] >> b[i];
a[i]--, b[i]--;
oc[a[i]]++, oc[b[i]]++;
}
int bad = 0;
for(int i = 0; i < N; i++){
bad += oc[i] % 2;
}
if(bad){
moo << "NO" << endl << bad/2 << endl;
return 0;
}
moo << "YES" << endl;
vis[0] = true;
dfs(0);
for(int i = 0; i < Q; i++){
dfsd(b[i], -1, 0);
vector<int> ans;
int v = a[i];
ans.push_back(v);
while(v != b[i]){
for(int j : tg[v]){
if(d[j] < d[v]) v = j;
}
ans.push_back(v);
}
moo << ans.size() << endl;
for(int j : ans) moo << j+1 << ' ';
moo << endl;
}
}