Created
August 31, 2019 20:52
-
-
Save chinchila/8e5681bf70f73594506bdcde99727b55 to your computer and use it in GitHub Desktop.
Virus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
#define MAXN 1010 | |
vector<int> g[MAXN]; | |
int n, m, mx; | |
int lvl[MAXN], dp[MAXN], sub[MAXN]; | |
void dfs( int u ){ | |
dp[u] = 0; | |
sub[u] = 1; | |
for( int v : g[u] ) { | |
if( !lvl[v] ) { | |
lvl[v] = lvl[u] + 1; | |
dfs( v ); | |
dp[u] += dp[v]; | |
sub[u] += sub[v]; | |
} | |
else if( lvl[v] < lvl[u] ) ++dp[u]; | |
else if( lvl[v] > lvl[u] ) --dp[u]; | |
} | |
--dp[u]; | |
if( lvl[u] > 1 && !dp[u] ) { | |
mx = max( mx, sub[u] ); | |
} | |
} | |
int | |
main() { | |
int T; | |
scanf( " %d", &T); | |
while( T-- ) { | |
int c; | |
scanf( " %d%d%d", &n, &m, &c ); | |
for( int i = 0, u, v ; i < m ; ++i ) { | |
scanf( " %d%d", &u, &v ); | |
g[u].push_back( v ); | |
g[v].push_back( u ); | |
} | |
lvl[c] = 1; | |
dfs( c ); | |
cout << mx << endl; | |
memset( g, 0, sizeof( g ) ); | |
memset( lvl, 0, sizeof( lvl ) ); | |
mx = 0 ; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment