Skip to content

Commit

Permalink
Merge pull request #1 from AlgoLeadMe/1-yuyu0830
Browse files Browse the repository at this point in the history
1-yuyu0830
  • Loading branch information
yuyu0830 authored Mar 15, 2024
2 parents 1a40b1c + c500c5f commit 5b6a343
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions yuyu0830/ํƒ์ƒ‰/1865.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// ์ตœ๋‹จ ๊ฒฝ๋กœ ๊ณจ๋“œ 3 ์›œํ™€ https://www.acmicpc.net/problem/1865
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>

#define MAX 9999999
#define SIZE 502
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

using namespace std;

struct edge {
int s, e, v;
};

bool f() {
int n, road, wormhole; cin >> n >> road >> wormhole;

int s, e, v;
vector<edge> edges;

// input
while (road--) {
cin >> s >> e >> v; // start, end, value
edges.push_back({s, e, v});
edges.push_back({e, s, v});
}

while (wormhole--) {
cin >> s >> e >> v;
edges.push_back({s, e, -v});
}

// Search all nodes n time
vector<int> dist(n + 1, MAX);
dist[1] = 0;

for (int node = 1; node <= n; node++) {
for (auto next : edges) {
s = next.s;
e = next.e;
v = next.v;

if (dist[e] > dist[s] + v)
dist[e] = dist[s] + v;
}
}

// Search one more time
for (auto next : edges) {
s = next.s;
e = next.e;
v = next.v;

if (dist[e] > dist[s] + v)
return true;
}

return false;
}

int main() {
fastio;
int testCase; cin >> testCase;
while (testCase--) {
if (f()) printf("YES\n");
else printf("NO\n");
}
}

0 comments on commit 5b6a343

Please sign in to comment.