Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- XR Interaction Toolkit
- BFS
- 다이나믹 프로그래밍
- Unreal Engine 5
- 정렬
- 구현
- 유니티
- Team Fortress 2
- 누적 합
- 유니온 파인드
- 시뮬레이션
- 우선순위 큐
- DFS
- 알고리즘
- 브루트포스
- ue5
- 수학
- 투 포인터
- 트리
- 자료구조
- 그리디 알고리즘
- 재귀
- 백트래킹
- 백준
- 다익스트라
- 그래프
- VR
- 스택
- 문자열
- c++
Archives
- Today
- Total
1일1알
백준 13424번 비밀 모임 C++ 본문
https://www.acmicpc.net/problem/13424
13424번: 비밀 모임
입력 데이터는 표준 입력을 사용한다. 입력은 T개의 테스트 데이터로 구성된다. 입력의 첫 번째 줄에 테스트 케이스의 개수를 나타내는 자연수 T가 주어진다. 각 테스트 케이스의 첫째 줄에는 방
www.acmicpc.net
플로이드-워셜
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int t, n, m;
vector<vector<int>> graph;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> t;
while (t--) {
cin >> n >> m;
graph = vector<vector<int>>(n + 1, vector<int>(n + 1, -1));
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
graph[a][b] = c;
graph[b][a] = c;
}
for (int i = 1; i <= n; i++) graph[i][i] = 0;
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (graph[i][k] == -1) continue;
if (graph[k][j] == -1) continue;
if (graph[i][j] == -1) graph[i][j] = graph[i][k] + graph[k][j];
else graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
}
}
}
int k;
cin >> k;
vector<int> friends(k);
for (int i = 0; i < k; i++) {
cin >> friends[i];
}
int minDist = INT_MAX;
int room = -1;
for (int i = 1; i <= n; i++) {
int sum = 0;
for (int j = 0; j < k; j++) {
int currRoom = friends[j];
sum += graph[currRoom][i];
}
if (sum < minDist) {
minDist = sum;
room = i;
}
}
cout << room << "\n";
}
}
'알고리즘' 카테고리의 다른 글
백준 22252번 정보 상인 호석 C++ (0) | 2022.11.27 |
---|---|
백준 10703번 유성 C++ (0) | 2022.11.26 |
백준 10025번 게으른 백곰 C++ (0) | 2022.11.24 |
백준 3495번 아스키 도형 C++ (0) | 2022.11.23 |
백준 15922번 아우으 우아으이야!! C++ (0) | 2022.11.22 |