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 reset(A) memset(A, 0, sizeof(A))
- const int mod = 1e9 + 7;
- using namespace std;
- int v[1005][1005];
- int n, m;
- vector<pair<int, int>> res;
- int check[1005];
- void dfs(int u)
- {
- check[u] = 1;
- // cout << u << " ";
- for(int i = 1; i <= n; i++)
- {
- if(v[u][i] && check[i] == 0)
- {
- dfs(i);
- }
- }
- }
- void solve()
- {
- cin >> n >> m;
- res.clear();
- reset(v);
- int x, y;
- for(int i = 0; i < m; i++)
- {
- cin >> x >> y;
- v[x][y] = 1;
- v[y][x] = 1;
- }
- for(int i = 1; i < n; i++)
- {
- for(int j = i + 1; j <= n; j++)
- {
- if(v[i][j])
- {
- reset(check);
- v[i][j] = 0;
- v[j][i] = 0;
- dfs(1);
- bool ok = true;
- for(int k = 1; k <= n; k++)
- {
- if(check[k] == 0)
- {
- ok = false;
- break;
- }
- }
- if(!ok)
- {
- cout << i << " " << j << " ";
- }
- v[i][j] = 1;
- v[j][i] = 1;
- }
- }
- }
- cout << el;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);cin.tie(0);
- int t = 1;
- cin >> t;
- // cin.ignore();
- while(t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement