Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstring>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int n, m, cnt = 0, a, b, v, arr[101][101], lamps[101];
- void dfs(int v)
- {
- lamps[v] = 1;
- // cout << v + 1 << " ";
- for (int i = 0; i < n; i++)
- {
- if(arr[v][i] == 1 && lamps[i] == 0)
- {
- cout << v + 1 << " " << i + 1 << "\n";
- dfs(i);
- }
- }
- }
- int main()
- {
- //--------------------------------
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- //--------------------------------
- cin >> n >> m;
- for (int i = 0; i < m; i++)
- {
- cin >> a >> b;
- arr[a-1][b-1] = arr[b-1][a-1] = 1;
- }
- dfs(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement