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 pair<int, int> pii;
const int N = 110;
const int K = 1e3+10;
const ll INF = 1e18;
ll b[N][K], s[N][K], w[N][N], mxv[N][N], g2[N][N], n, m, k;
void floyd(ll g[N][N]) {
for (int k=1; k<=n; ++k) {
for (int i=1; i<=n; ++i) {
for (int j=1; j<=n; ++j) g[i][j]=min(g[i][j], g[i][k]+g[k][j]);
}
}
}
void solve() {
cin>>n>>m>>k;
for (int i=1; i<=n; ++i) {
for (int j=1; j<=k; ++j) cin>>b[i][j]>>s[i][j];
for (int j=1; j<=n; ++j) w[i][j]=INF;
}
for (int i=1; i<=m; ++i) {
ll a, b, x; cin>>a>>b>>x;
w[a][b]=x;
} floyd(w);
for (int i=1; i<=n; ++i) {
for (int j=1; j<=n; ++j) {
for (int x=1; x<=k; ++x) {
if (b[i][x] == -1 || s[j][x] == -1) continue;
mxv[i][j]=max(mxv[i][j], s[j][x]-b[i][x]);
}
}
}
ll ans=0, l=1, r=1e9+10;
while (l <= r) {
ll md=(l+r)/2;
for (int i=1; i<=n; ++i) {
for (int j=1; j<=n; ++j) {
g2[i][j]=-mxv[i][j]+md*min(w[i][j], INF/md);
}
} floyd(g2);
bool ok=false;
for (int i=1; i<=n; ++i) {
if (g2[i][i] <= 0) ok=true;
}
if (ok) ans=md, l=md+1;
else r=md-1;
} cout<<ans<<"\n";
}
int main() {
int t=1;
while (t--) solve();
}
# | 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... |