SHARE
TWEET

Untitled

a guest Dec 9th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define maxn 500
  4. #define inf 0x3F3F3F3F
  5. vector <int> g[maxn];
  6. bool vis[maxn];
  7. int n, m, a, b;
  8. int cnt = 0;
  9. void dfs(int x){
  10.     vis[x] = true;
  11.     cnt++;
  12.     for(int i = 0; i < g[x].size(); i++){
  13.         int y = g[x][i];
  14.         if(vis[y] == false)
  15.             dfs(y);
  16.     }
  17. }
  18.  
  19. int main()
  20. {
  21.     int t, inicial;
  22.     cin >> t;
  23.     while(t--){
  24.         cnt = 0;
  25.         memset(vis, 0, sizeof vis);
  26.         cin >> inicial;
  27.         scanf("%d %d", &n, &m);
  28.         for(int i = 0; i < m; i++){
  29.             scanf("%d %d", &a, &b);
  30.             g[a].push_back(b);
  31.             g[b].push_back(a);
  32.         }
  33.         dfs(inicial);
  34.         cnt--;
  35.         cout << cnt*2 << endl;
  36.         for(int i = 0; i < n; i++)g[i].clear();
  37.     }
  38.     return 0;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top