Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define st first
  4. #define nd second
  5. #define pb push_back
  6. int t, n, m, a, b;
  7. vector<int>g[200005];
  8. int usea[200005];
  9. int useb[200005];
  10. int nra, nrb;
  11. void dfsa( int x )
  12. {
  13.     usea[x] = 1;
  14.     nra++;
  15.  
  16.     for( auto it : g[x] )
  17.         if( !usea[it] && it != b )
  18.             dfsa( it );
  19. }
  20. void dfsb( int x )
  21. {
  22.     useb[x] = 1;
  23.     nrb++;
  24.  
  25.     for( auto it : g[x] )
  26.         if( !useb[it] && it != a )
  27.             dfsb( it );
  28. }
  29. int main()
  30. {
  31.     cin >> t;
  32.  
  33.     while( t-- )
  34.         {
  35.             cin >> n >> m >> a >> b;
  36.             int x, y;
  37.             nra = nrb = 0;
  38.  
  39.             for( int i = 1; i <= n; i++ )
  40.                 {
  41.                     usea[i] = useb[i] = 0;
  42.                     g[i].clear();
  43.                 }
  44.  
  45.             for( int i = 1; i <= m; i++ )
  46.                 {
  47.                     cin >> x >> y;
  48.                     g[x].pb( y );
  49.                     g[y].pb( x );
  50.                 }
  51.  
  52.             dfsa( a );
  53.             dfsb( b );
  54.             x = n - nra - 1;
  55.             y = n - nrb - 1;
  56.             cout << ( long long )x*y << '\n';
  57.         }
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement