Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define ll long long
- #define forn(i, n, a) for(int i = a; i < n; i++)
- #define fora(i, n, a) for(int i = a; i > n; i--)
- #define f first
- #define s second
- #define pb push_back
- #define mp make_pair
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <stack>
- //#pragma comment(linker, "/STACK:156777237" )
- using namespace std;
- vector<int> map[1001], ostgr[1001];
- bool used[1001];
- void make_graph(int v)
- {
- used[v] = true;
- forn(i, map[v].size(), 0)
- {
- if (!used[map[v][i]])
- {
- ostgr[v].pb(map[v][i]);
- ostgr[map[v][i]].pb(v);
- make_graph(map[v][i]);
- }
- }
- }
- bool dfs(int a, int b, int co, int pa)
- {
- if(a == b)
- {
- cout << co << ' ';
- cout << a << ' ';
- return true;
- }
- forn(i, ostgr[a].size(), 0)
- {
- if (ostgr[a][i] != pa && dfs(ostgr[a][i], b, co + 1, a))
- {
- cout << a << ' ';
- return true;
- }
- }
- }
- int main(void) {
- //#ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- //#endif
- int n, m;
- cin >> n >> m;
- forn(i, m + 1, 1)
- {
- int x, y;
- cin >> x >> y;
- map[x].pb(y);
- map[y].pb(x);
- }
- make_graph(1);
- int c;
- cin >> c;
- forn(i, c, 0)
- {
- int a, b, c;
- cin >> a >> b >> c;
- dfs(b, a, 1, 0);
- cout << endl;
- dfs(c, a, 1, 0);
- cout << endl;
- dfs(c, b, 1, 0);
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement