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 <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF (1LL<<60)
#define MOD 1000000007
int N, M, K;
void warshall_floyd(long long D[100][100]) {
rep(k, N) rep(i, N) rep(j, N) D[i][j] = min(D[i][j], D[i][k]+D[k][j]);
}
long long B[100][1000], S[100][1000];
long long D[100][100];
long long profit[100][100];
long long cost[100][100];
bool f(int X) {
rep(i, N) rep(j, N) cost[i][j] = INF;
rep(a, N) rep(b, N) if (a != b && D[a][b] != INF) {
cost[a][b] = -(profit[a][b]-1LL*X*D[a][b]);
}
warshall_floyd(cost);
//cout<<"f("<<X<<"): ";rep(i, N) cout<<cost[i][i]<<",";cout<<"\n";
rep(i, N) if (cost[i][i] <= 0) return true;
return false;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> M >> K;
rep(i, N) rep(j, K) cin >> B[i][j] >> S[i][j];
rep(i, N) rep(j, N) D[i][j] = INF;
rep(i, N) D[i][i] = 0;
rep(i, M) {
int u, v, w;
cin >> u >> v >> w;
u--, v--;
D[u][v] = w;
}
rep(a, N) rep(b, N) if (a != b) {
long long m = 0;
rep(k, K) {
if (B[a][k] == -1 || S[b][k] == -1) continue;
m = max(m, S[b][k]-B[a][k]);
}
profit[a][b] = m;
}
warshall_floyd(D);
int lo = 0, hi = 2e9;
while (hi-lo>1) {
int mid=(0LL+lo+hi)/2;
if (f(mid)) lo = mid;
else hi = mid;
}
cout << lo << "\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... |