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<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define int ll
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()
bool calc(vvi &dist, vvi &profit, int &N, int R){
vvi G(N, vi(N, -INF));
for(int u = 0; u < N; u++){
for(int v = 0; v < N; v++){
if(u == v || dist[u][v] == INF) continue;
G[u][v] = profit[u][v] - R*dist[u][v];
}
}
for(int i = 0; i < N; i++)
for(int u = 0; u < N; u++)
for(int v = 0; v < N; v++)
G[u][v] = max(G[u][v], G[u][i]+G[i][v]);
for(int x = 0; x < N; x++)
if(G[x][x] >= 0) return true;
return false;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int N, M, K; cin >> N >> M >> K;
vector<vvi> C(N, vvi(K, vi(2))); // C[i][k] = {buy, sell}
for(int x = 0; x < N; x++)
for(int k = 0; k < K; k++)
cin >> C[x][k][0] >> C[x][k][1];
vvi dist(N, vi(N, INF)), profit(N, vi(N));
while(M--){
int u, v, c; cin >> u >> v >> c;
u--, v--; dist[u][v] = c;
}
for(int x = 0; x < N; x++) dist[x][x] = 0;
for(int i = 0; i < N; i++)
for(int u = 0; u < N; u++)
for(int v = 0; v < N; v++)
dist[u][v] = min(dist[u][v], dist[u][i]+dist[i][v]);
for(int u = 0; u < N; u++){
for(int v = 0; v < N; v++){
for(int k = 0; k < K; k++){
if(C[u][k][0] != -1 && C[v][k][1] != -1)
profit[u][v] = max(profit[u][v], C[v][k][1]-C[u][k][0]);
}
}
}
int low = 0, high = 1e9;
while(low < high){
int mid = (low+high+1)/2;
if(calc(dist, profit, N, mid)) low = mid;
else high = mid-1;
}
cout << low << endl;
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... |