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 a[1005][2];
- 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;
- a[i][0] = x;
- a[i][1] = y;
- v[x][y] = 1;
- v[y][x] = 1;
- }
- for(int i = 0; i < m; i++)
- {
- reset(check);
- v[a[i][0]][a[i][1]] = 0;
- v[a[i][1]][a[i][0]] = 0;
- // cout << el << el;
- dfs(1);
- // cout << el << el;
- bool ok = true;
- for(int j = 1; j <= n; j++)
- {
- if(check[j] == 0)
- {
- ok = false;
- break;
- }
- }
- if(!ok)
- {
- cout << a[i][0] << " " << a[i][1] << " ";
- }
- v[a[i][0]][a[i][1]] = 1;
- v[a[i][1]][a[i][0]] = 1;
- }
- // for(int i = 0; i < res.size(); i++)
- // {
- // cout << res[i].first << " " << res[i].second << " ";
- // }
- 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