Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define el endl
- #define umi unordered_map<int, int>
- #define umll unordered_map<ll, ll>
- #define all(vect) vect.begin(), vect.end()
- #define reseta(A) memset(A, 0, sizeof(A))
- const int mod = 1e9 + 7;
- using namespace std;
- int v[1005][1005];
- int n, m;
- bool check[1005];
- void reset()
- {
- for(int i = 0; i <= n; i++)
- check[i] = true;
- }
- void dfs(int u)
- {
- check[u] = false;
- // cout << u << " ";
- for(int i = 1; i <= n; i++)
- {
- if(v[u][i] && check[i])
- {
- dfs(i);
- }
- }
- }
- bool kt(int i, int j)
- {
- reset();
- dfs(1);
- for(int k = 1; k <= n; k++)
- {
- if(check[k])
- return false;
- }
- return true;
- }
- void solve()
- {
- cin >> n >> m;
- int x, y;
- for(int i = 0; i < m; i++)
- {
- cin >> x >> y;
- v[x][y] = v[y][x] = 1;
- }
- for(int i = 1; i < n; i++)
- {
- for(int j = i + 1; j <= n; j++)
- {
- if(v[i][j])
- {
- v[i][j] = v[j][i] = 0;
- if(!kt(i, j))
- cout << i << " " << j << " ";
- v[i][j] = v[j][i] = 1;
- }
- }
- }
- cout << el;
- }
- int main()
- {
- int t = 1;
- cin >> t;
- // cin.ignore();
- while(t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement