P2648 赚钱https://www.luogu.com.cn/problem/P2648
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
#include <cstdlib>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 1000010;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) ((x)&(-x))
int D, P, C, F;
int s[355][355], d[355], v[355], cnt[355];
inline void Floyd() {
for (int k = 1; k <= C; k++) {
for (int i = 1; i <= C; i++) {
for (int j = 1; j <= C; j++) {
s[i][j] = max(s[i][j], s[i][k] + s[k][j]);
}
}
}
}
int main() {
memset(s, 0xc0, sizeof(s));
int x, y, c;
scanf("%d %d %d %d", &D, &P, &C, &F);
for (int i = 1; i <= P; i++) {
scanf("%d %d", &x, &y);
s[x][y] = D;
}
for (int i = 1; i <= F; i++) {
scanf("%d %d %d", &x, &y, &c);
s[x][y] = D - c;
}
Floyd();
int ans1 = 0;
int ans2 = 0;
for (int i = 1; i <= C; i++) {
for (int j = 1; j <= C; j++) {
ans1 = max(ans1, s[i][j]);
}
}
Floyd();
for (int i = 1; i <= C; i++) {
for (int j = 1; j <= C; j++) {
ans2 = max(ans2, s[i][j]);
}
}
//printf("%d", ans1 + D);
if (ans1 != ans2) {
printf("orz");
} else {
printf("%d", ans1 + D);
}
return 0;
}
#if 0
int D, P, C, F;
int head[MAXN];
int nxt[MAXN];
int ver[MAXN];
int cost[MAXN];
int cnt;
int rec[MAXN];
int d[MAXN];
inline void add(int x, int y, int c) {
ver[++cnt] = y;
nxt[cnt] = head[x];
cost[cnt] = c;
head[x] = cnt;
}
bool vis[MAXN];
inline bool spfa(int s) {
memset(vis, 0, sizeof(vis));
memset(rec, 0, sizeof(rec));
memset(d, 128, sizeof(d));
queue<int> que;
que.push(s);
d[s] = 0;
vis[s] = true;
while (!que.empty()) {
int x = que.front();
que.pop();
vis[x] = false;
for (int i = head[x]; i; i = nxt[i]) {
int y = ver[i], c = cost[i];
if (d[y] > d[x] + c) {
d[y] = d[x] + c;
rec[y] = rec[x] + 1;
if (rec[y] > C) {
return true;
}
if (!vis[y]) {
que.push(y);
vis[y] = true;
}
}
}
}
return false;
}
int main() {
int x, y, c;
scanf("%d %d %d %d", &D, &P, &C, &F);
for (int i = 1; i <= P; i++) {
scanf("%d %d", &x, &y);
add(x, y, -D);
}
for (int i = 1; i <= F; i++) {
scanf("%d %d %d", &x, &y, &c);
add(x, y, c - D);
}
int ans = 0;
for (int i = 1; i <= C; i++) {
if (spfa(i)) {
printf("orz");
return 0;
} else {
for (int i = 1; i <= C; i++) {
ans = max(ans, -d[i]);
}
}
}
printf("%d", ans + D);
return 0;
}
#endif