목록전체 글 (370)
cgy12306
// https://www.acmicpc.net/problem/1504 // 특정한 최단 경로 #include #include #include #include using namespace std; int N, E, INF = 999999999; int minCost[802]; vector Edge; void dijkstra(int start) { fill(minCost, minCost + N + 1, INF); priority_queue pq; pq.push(make_pair(0, start)); minCost[start] = 0; while (!pq.empty()) { int cost = -pq.top().first; int current = pq.top().second; pq.pop(); if (mi..
// https://www.acmicpc.net/problem/1238 // 파티 #include #include #include #include #include using namespace std; int N, M, X, Max = 0, INF = 999999999, ans = 0; int minCost[1002]; vector Edge; void dijkstra(int start) { fill(minCost, minCost + N + 1, INF); priority_queue pq; pq.push(make_pair(0, start)); minCost[start] = 0; while (!pq.empty()) { int cost = -pq.top().first; int current = pq.top()...
// https://www.acmicpc.net/problem/11581 // 구호물자 #include #include using namespace std; int N, INF = 999999999; bool arr[102][102]; void floyd() { for (int k = 1; k
우선순위 큐에 second 값을 이용하여 비교하는 방식은 시간초과가 발생함. first로 비교해야 함 // https://www.acmicpc.net/problem/1753 // 최단경로 #include #include #include #include using namespace std; int V, E, start, INF = 999999999; int minCost[20001]; vector Edge; void dijkstra(int start) { priority_queue pq; minCost[start] = 0; pq.push(make_pair(0, start)); while (!pq.empty()) { int cost = -pq.top().first; int current = pq.top()...
// https://www.acmicpc.net/problem/1916 // 최소비용 구하기 #include #include #include using namespace std; int N, M, INF = 999999999; vector V; int minCost[1001]; void dijkstra(int start) { priority_queue pq; minCost[start] = 0; pq.push(make_pair(start, 0)); while (!pq.empty()) { int current = pq.top().first; int cost = -pq.top().second; pq.pop(); if (minCost[current] < cost) continue; for (int i = 0; ..
// https://www.acmicpc.net/problem/2660 // 회장뽑기 #include #include #include using namespace std; int N, arr[52][52], INF = 999999999; void floyd_warshall() { for (int k = 1; k > from >> to; if (from == -1 && to == -1) break; arr[from][to] = 1; arr[to][from] = 1; } floyd_warshall(); for (int i = 1; i
BFS // https://www.acmicpc.net/problem/9205 // 맥주 마시면서 걸어가기 // BFS #include #include #include #include #include using namespace std; int T, N, x, y, festival_x, festival_y; bool happy_flag; void bfs(vector &v) { queue que; while (!que.empty()) que.pop(); que.push(make_tuple(get(v[0]), get(v[0]), get(v[0]))); while (!que.empty()) { int x = get(que.front()); int y = get(que.front()); if (x == fest..
// https://www.acmicpc.net/problem/11404 // 플로이드 #include #include #include using namespace std; int n, m, city[102][102], INF = 99999999; void floyd_warshall() { for (int k = 1; k > m; fill(city[0], city[102], INF); for (int i = 0; i > from >> to >> cost; if (city[from][to] > cost) { city[from][to] = cost; } } floyd_warshall(); for (int i = 1; i
// https://www.acmicpc.net/problem/11403 // 경로 찾기 #include #include using namespace std; int N; int arr[101][101]; void floyd_warshall() { for (int k = 0; k > N; for (int i = 0; i < N; i++) { f..
// https://www.acmicpc.net/problem/6603 // 로또 #include #include #include #include using namespace std; int K, arr[50], tmparr[7]; bool visited[50]; void dfs(int cnt, int num) { if (cnt == 6) { for (int i = 0; i < cnt; i++) { cout arr[k]; } dfs(0, 0); cout