Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions kangrae-jo/Graph/34-kangrae-jo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1e9;

bool solution(vector<vector<pair<int,int>>>& graph, int N) {
vector<int> dist(N + 1, 0);
for (int i = 1; i <= N; i++) {
bool updated = false;
for (int from = 1; from <= N; from++) {
for (auto [to, cost] : graph[from]) {
if (dist[to] > dist[from] + cost) {
dist[to] = dist[from] + cost;
updated = true;
if (i == N) return true;
}
}
}
if (!updated) break;
}

return false;
}

int main() {
int TC;
cin >> TC;

while (TC--) {
int N, M, W;
cin >> N >> M >> W;

vector<vector<pair<int, int>>> graph(N + 1);
for (int i = 0; i < M; i++) {
int S, E, T;
cin >> S >> E >> T;

graph[S].push_back({E, T});
graph[E].push_back({S, T});
}

for (int i = 0; i < W; i++) {
int S, E, T;
cin >> S >> E >> T;

graph[S].push_back({E, -T});
}

if (solution(graph, N)) cout << "YES\n";
else cout << "NO\n";
}

return 0;
}
3 changes: 2 additions & 1 deletion kangrae-jo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
| 28์ฐจ์‹œ | 2024.06.10 | BFS | [๊ฒฝ์ฃผ๋กœ ๊ฑด์„ค](https://school.programmers.co.kr/learn/courses/30/lessons/67259)|[#110](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/110)|
| 29์ฐจ์‹œ | 2024.06.19 | TRIE | [[3์ฐจ] ์ž๋™์™„์„ฑ](https://school.programmers.co.kr/learn/courses/30/lessons/17685)|[#114](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/114)|
| 30์ฐจ์‹œ | 2024.07.18 | BFS | [์น˜์ฆˆ](https://www.acmicpc.net/problem/2638)|[#117](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/117)|
| 31์ฐจ์‹œ | 2024.07.31 | Prefix Sum | [๋‘ ๋ฐฐ์—ด์˜ ํ•ฉ](https://www.acmicpc.net/problem/2143)|[#122](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/122)|
| 31์ฐจ์‹œ | 2024.07.31 | Prefix Sum | [๋‘ ๋ฐฐ์—ด์˜ ํ•ฉ](https://www.acmicpc.net/problem/2143)|[#122](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/122)|
| 34์ฐจ์‹œ | 2024.08.28 | Graph | [์›œํ™€](https://www.acmicpc.net/problem/1865)|[#122](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/136)|