알고리즘/SWEA

[SWEA 1219] 길찾기

히더 2018. 8. 10. 15:44

출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14geLqABQCFAYD


#include <iostream>

#include <algorithm>

#include <memory.h>

using namespace std;


int N,result;

int a[100], b[100];


void dfs(int now)

{

if (a[now] == 99 || b[now] == 99) { result = 1; return; }

else

{

if(a[now]!=-1)dfs(a[now]);

if (b[now] != -1)dfs(b[now]);

}

}


int main()

{

int T; int t;

T = 10;

while (T--)

{

cin >> t >> N; result = 0; 

fill(a,a+100, -1); fill(b,b+100, -1);

for (int i = 0; i < N; i++)

{

int n1, n2; cin >> n1 >> n2;

if (a[n1] == -1) a[n1] = n2;

else b[n1] = n2;

}

dfs(0);

cout << "#" << t << " " << result << endl;

}


return 0;

}