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;
- bool check[1005];
- void khoitao(){
- for(int i=1;i<=n;i++) check[i]=0;
- }
- void dfs(int u){
- check[u] = 1;
- for(int i = 1; i <= n; i++)
- if(v[u][i] && check[i] == 0)
- dfs(i);
- }
- int ktcanhcau(){
- khoitao();
- dfs(1);
- for(int i=1;i<=n;i++){
- if(check[i]==0) return 1;
- }
- return 0;
- }
- void solve()
- {
- cin >> n >> m;
- 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]==1)
- {
- v[i][j] = v[j][i] = 0;
- if(ktcanhcau()==1)
- {
- cout << i << " " << j << " ";
- }
- v[i][j] = v[j][i] = 1;
- }
- }
- }
- cout << el;
- }
- int main(){
- int t ;
- cin >> t;
- while(t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement