-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from AlgoLeadMe/1-yuyu0830
1-yuyu0830
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |