Written by
nodejs-style
on
on
[백준 2606] 바이러스 (C++)
[백준 2606] 바이러스 (C++)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include < iostream > using namespace std ; bool graph[ 101 ][ 101 ]; bool visited[ 101 ]; int n, m; int cnt; void dfs( int node) { if (visited[node]) return ; visited[node] = true ; for ( int i = 1 ; i < 101 ; i + + ) { if (graph[node][i]) { if ( ! visited[i]) { cnt + + ; dfs(i); } } } } int main() { cin > > n > > m; for ( int i = 0 ; i < m; i + + ) { int a, b; cin > > a > > b; graph[a][b] = true ; graph[b][a] = true ; } dfs( 1 ); cout < < cnt < < endl ; return 0 ; }
from http://gamedoridori.tistory.com/25 by ccl(A) rewrite - 2021-09-04 23:00:38