0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-28 14:31:58 +00:00

P1938 [USACO09NOV]Job Hunt S

R53992295
This commit is contained in:
Baoshuo Ren 2021-07-23 15:16:48 +08:00 committed by Baoshuo Ren
parent 68a6439641
commit a5e85d9936
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using namespace std;
int d, p, c, f, s, t, dist[505], x;
struct node {
int u, v, w;
} g[1005];
int main() {
cin >> d >> p >> c >> f >> s;
for (int i = 1; i <= p; i++) {
cin >> g[i].u >> g[i].v;
g[i].w = -d;
}
for (int i = p + 1; i <= p + f; i++) {
cin >> g[i].u >> g[i].v >> t;
g[i].w = t - d;
}
memset(dist, 0x3f, sizeof(dist));
dist[s] = 0;
for (int i = 1; i <= c; i++) {
for (int j = 1; j <= p + f; j++) {
dist[g[j].v] = min(dist[g[j].v], dist[g[j].u] + g[j].w);
}
}
for (int i = 1; i <= p + f; i++) {
if (dist[g[i].v] > dist[g[i].u] + g[i].w) {
cout << -1 << endl;
exit(0);
}
}
dist[0] = 0x3f3f3f3f;
for (int i = 1; i <= c; i++) {
x = dist[i] < dist[x] ? i : x;
}
cout << d - dist[x] << endl;
return 0;
}