๋ฌธ์์ด๋ก ๋ฐ์์ผ๋ ์์คํค์ฝ๋ 48๋งํผ ๋นผ์ฃผ๋ ๊ฑฐ ์์ง ๋ง๊ธฐ #include #include #include #include #define INF (int(1e9)) using namespace std; struct Edge { int pos[2]; int cost; }; struct cmp { bool operator() (Edge a, Edge b) { if (a.cost d[cur.pos[0]][cur.pos[1]]) continue; for(int i = 0; i = N || nc >= M) continue; if (d[nr][nc] > M >> N; mem..
๊ฒฝ๋ก ์ ์ฅ๋ฐฉ์ ์ฃผ์! ๋ค์ต์คํธ๋ผ ์งํํ ๋ ์ฌ์ฉํ๋ ๋ฐฐ์ด๊ณผ ์ต์ข ๋ฃจํธ๋ฅผ ์ ์ฅํ ๋ฐฐ์ด ์ถ๊ฐ if (d[next.to] = b.cost) return false; else return true; } }; int n, m; vector graph[1005]; // ๋ฒ์ค ์ ๋ณด vector t_route; int route[1005]; int d[1005]; // ์ถ๋ฐ ์ง์ ์์ ๊ฐ ์ง์ ๊น์ง์ ๊ฑฐ๋ฆฌ void dijkstra(int s) { priority_queue pq; pq.push({s, 0}); d[s] = 0; int i = 0; while(!pq.empty()) { Edge cur = pq.top(); pq.pop(); // cout m; int s, e, c; for (int i = 0; i < m ;..
BFS + ๋ค์ต์คํธ๋ผ cmp ๋ถํธ ์ฃผ์ #include #include #include #define INF int(1e9) using namespace std; struct Edge{ int pos[2]; int cost; }; struct cmp { bool operator() (Edge a, Edge b) { if (a.cost d[cur.pos[0]][cur.pos[1]]) continue; for(int i = 0; i = N || nc >= N) continue; if (d[nr][nc] > N; while (N != 0..
#include #include #include #include #define INF int(1e9) using namespace std; struct Edge { int to; int cost; }; struct cmp { bool operator() (Edge a, Edge b) { if (a.cost n >> m >> x; // ์ ์ ๊ฐฏ์, ๊ฐ์ ๊ฐฏ์, ๋์ฐฉ์ง์ int s, e, t; for (int i = 0; i > s >> e >> t; graph[s].push_back({e, t}); // to, cost } memset(total_d, 0, sizeof(total_d)); for (int i = 1; i
๋ค์ต์คํธ๋ผ ์ฌ์ฉํ๋ค๊ณ ๋ฌด์กฐ๊ฑด ์ด์ค vector ๋ฃ์ ํ์ ์์. ์ด ๋ฌธ์ ์ ๊ฒฝ์ฐ graph์ ๊ฐ๊ฐ 3๊ฐ์ ๊ฐ์ ๋ฃ์๋๋ runtime error graph ๋์ ์กฐ๊ฑด๋ฌธ์ผ๋ก ๋ฐ๊ฟจ๋๋ ๋ฉ๋ชจ๋ฆฌ ์ด๊ณผ ์๋จ ์ดํ ๋ ํ๋ ธ๋๋ฐ if(b > k * 2) ๋ผ๋ ์ด์ํ ์กฐ๊ฑด๋ฌธ ๋ฃ์ด์ ํ๋ฆผ // graph ์ ๊ฐ๊ฐ 3๊ฐ์ ๊ฐ์ ๋ฃ์ผ๋ฉด runtime error // graph ๋์ ์กฐ๊ฑด๋ฌธ์ผ๋ก bad alloc ์์ฐ // if(b > k * 2) ๋ผ๋ ์ด์ํ ์กฐ๊ฑด๋ฌธ ๋ฃ์ด์ ํ๋ฆผ #include #include #include #define INF int(1e5) using namespace std; struct Edge { int to; int cost; }; struct cmp { bool operator() (Edge a..