본문 바로가기

백준 알고리즘/BFS47

백준 1967번 C++ #include #include #include #include #include using namespace std; const int MAX = 10001; vector tree[MAX]; int n; int visited[MAX]; pair bfs(int i) { pair answer; queue q; q.push(make_pair(i, 0)); answer = make_pair(0, -1); while (!q.empty()) { int current = q.front().first; int value = q.front().second; q.pop(); if (answer.second < value) answer = make_pair(current, value); for (int k = 0; k < .. 2019. 8. 19.
백준 9019번 C++ #include #include #include #include using namespace std; const int MAX = 10001; const int MOD = 10000; int visited[MAX]; void bfs(int start, int end) { queue q; q.push(make_pair(start,"")); visited[start] = 1; while (!q.empty()) { int current = q.front().first; string cmd = q.front().second; q.pop(); if (current == end) { cout testcase; for (int i = 0; i < testcase; i++) { memset(visited, -1, si.. 2019. 8. 18.
백준 2146번 C++ #include #include #include #include using namespace std; const int MAX = 101; int n; int map[MAX][MAX]; int visited[MAX][MAX]; struct Move { int x, y; }; Move mv[4] = { {-1,0}, {1,0}, {0,1}, {0,-1} }; void dfs(int i, int j,int index) { map[i][j] = index; for (int k = 0; k = 0 && movei = 0 && movej < n) { if (v.. 2019. 8. 17.
백준 1963번 C++ #include #include #include #include #include using namespace std; const int MAX = 10000; int prime[MAX]; int visited[MAX]; char increase[10] = { '0','1','2','3','4','5', '6','7','8','9' }; void calprime() { for (int i = 1000; i testcase; memset(prime, 0,sizeof(prime)); calprime(); for (int i = 0; i > first >> sec.. 2019. 8. 16.