본문 바로가기

백준 알고리즘/BFS47

백준 2573번 C++ #include #include #include #include using namespace std; const int MAX = 301; int n, m; int map[MAX][MAX]; queue q; int visited[MAX][MAX]; int copys[MAX][MAX]; struct Move { int x, y; }; Move mv[4] = { {1,0}, {-1,0} ,{0,1}, {0,-1} }; bool divide() { for (int i = 0; i 0 && visited[i][j] == -1) return true; } } return false; } void bfs() .. 2019. 8. 15.
백준 2206번 C++ #include #include #include using namespace std; const int MAX = 1000; int map[MAX][MAX]; int n, m; int visited[MAX][MAX][2]; struct Move { int x, y; }; Move mv[4] = { {1,0}, {-1,0} ,{0,1}, {0,-1} }; int bfs() { queue q; q.push(make_pair(0,make_pair(0,1))); visited[0][0][1] = 1; while (!q.empty()) { int currenti = q.front().first; int currentj = q.front().second.first; int broke = q.front().secon.. 2019. 8. 15.
백준 3055번 C++ #include #include #include #include using namespace std; const int MAX = 51; string map[MAX]; int r, c; queue water,moves; pair room; int visited2[MAX][MAX]; struct Move { int x, y; }; Move mv[4] = { {1,0},{-1,0},{0,1},{0,-1} }; int bfs() { while (!moves.empty()) { int watersize = water.size(); for (int i = 0; i < watersize; i++) { int currenti = water.front().first; int currentj = water.front().. 2019. 8. 14.
백준 1707번 C++ #include #include #include using namespace std; const int MAX = 20001; int v, e, flag; int floors[MAX]; vector graph[MAX]; void dfs(int point, int group) { floors[point] = group; for(int i=0; i> testcase; for (int k = 0; k > v >> e; flag = 0; for (int j = 0; j < MAX; j++) graph[j].clear(); memset(floors, -1, sizeof(floors)); for (int i = 0; i < e; i++) { int start, end; c.. 2019. 8. 14.