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>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 1e2 + 5, maxk = 1e3 + 5, lg = 22, inf = ll(1e18) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
ll adj[maxn][maxn], adj2[maxn][maxn], s[maxn][maxk], b[maxn][maxk], prof[maxn][maxn];
int n;
void feloyd(ll adj[maxn][maxn]){
rep(k,0,n) rep(i,0,n) rep(j,0,n) adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
int m, k; cin >> n >> m >> k;
rep(i,0,n){
rep(j,0,k) cin >> b[i][j] >> s[i][j];
}
rep(i,0,n) rep(j,0,n) adj[i][j] = inf;
rep(i,0,m){
int u, v, w; cin >> u >> v >> w; u--, v--;
adj[u][v] = w;
}
feloyd(adj);
rep(i,0,n) rep(j,0,n) rep(t,0,k) if(s[j][t] + 1 && b[i][t] + 1) prof[i][j] = max(prof[i][j], s[j][t] - b[i][t]);
ll l = 0, r = ll(1e9) + 5;
while(l + 1 < r){
ll mid = (l + r)>>1ll;
rep(i,0,n) rep(j,0,n) {
if(adj[i][j] == inf) adj2[i][j] = inf;
else adj2[i][j] = mid*adj[i][j] - prof[i][j];
}
feloyd(adj2);
bool ok = false;
rep(i,0,n) if(adj2[i][i] <= 0) ok = true;
(ok?l:r) = mid;
}
cout << l << '\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... |