This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <vector>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <sstream>
using namespace std;
using int64 = long long;
const double EPS = 1e-9;
const int64 INF = (1LL<<60);
struct Market {
int b;
int s;
};
int N, M, K;
vector<vector<Market>> market;
vector<vector<int64>> dist;
vector<vector<int>> profit;
bool go(int64 r) {
vector<vector<int64>> d(N, vector<int64>(N, INF));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i != j && dist[i][j] < INF) {
d[i][j] = min(d[i][j], -profit[i][j] + r * dist[i][j]);
}
}
}
for (int k = 0; k < N; k++)
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
for (int i = 0; i < N; i++) {
if (d[i][i] <= 0)
return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> M >> K;
market = vector<vector<Market>>(N, vector<Market>(K));
for (int i = 0; i < N; i++) {
for (int j = 0; j < K; j++) {
cin >> market[i][j].b >> market[i][j].s;
}
}
dist = vector<vector<int64>>(N, vector<int64>(N, INF));
for (int i = 0; i < N; i++)
dist[i][i] = 0;
for (int i = 0; i < M; i++) {
int x, y, w;
cin >> x >> y >> w;
x--, y--;
dist[x][y] = min(dist[x][y], (int64)w);
}
for (int k = 0; k < N; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
profit = vector<vector<int>>(N, vector<int>(N));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (dist[i][j] < INF) {
for (int k = 0; k < K; k++) {
if (market[i][k].b != -1 && market[j][k].s != -1) {
profit[i][j] = max(profit[i][j], market[j][k].s - market[i][k].b);
}
}
}
}
}
int64 l = 1, r = (1LL<<30), sol = 0;
while (l <= r) {
int64 m = (l + r) >> 1;
if (go(m)) {
sol = m;
l = m + 1;
} else {
r = m - 1;
}
}
cout << sol << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |