This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O2,unroll-loops,inline")
#pragma GCC target("avx2,bmi,bmi2,popcnt")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define endl '\n'
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define plll pair<pll,pll>
#define open(name) if(fopen(name".inp", "r")){freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
using namespace std;
const int maxN=102;
const int mod=998244353;
ll n,m,k,a[maxN][1002],b[maxN][1002],d[maxN][maxN],c[maxN][maxN],dis[maxN][maxN];
vector<pll> adj[maxN];
void dijkstra(ll s){
priority_queue<pll,vector<pll>,greater<pll>> pq;
memset(d[s],1,sizeof d[s]);
pq.push({0,s});d[s][s]=0;
while(!pq.empty()){
ll dist=pq.top().first,u=pq.top().second;pq.pop();
if(d[s][u]<dist)continue;
for(auto x:adj[u]){
ll v=x.first,w=x.second;
if(d[s][v]>d[s][u]+w)d[s][v]=d[s][u]+w,pq.push({d[s][v],v});
}
}
}
bool check(ll x){
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
if(i!=j&&d[i][j]<1e12)dis[i][j]=x*d[i][j]-c[i][j];
else dis[i][j]=1e18;
for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
for(int i=1;i<=n;i++)if(dis[i][i]<=0)return 1;
return 0;
}
void Enter(){
cin>>n>>m>>k;
for(int i=1;i<=n;i++)for(int j=1;j<=k;j++)cin>>a[i][j]>>b[i][j];
for(int i=1;i<=m;i++){
ll u,v,w;cin>>u>>v>>w;
adj[u].pb({v,w});
}
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)for(int z=1;z<=k;z++)if(b[j][z]!=-1&&a[i][z]!=-1)c[i][j]=max(c[i][j],b[j][z]-a[i][z]);
for(int i=1;i<=n;i++)dijkstra(i);
ll l=0,r=1e9+2;
while(l<r){
ll mid=l+r>>1;
if(check(mid))l=mid+1;
else r=mid;
}
cout<<l-1;
}
//amogus
signed main(){
//open("tbrackets");
cin.tie(nullptr);ios_base::sync_with_stdio(NULL);
//ll t=1;cin>>t;while(t--)
Enter();
}
Compilation message (stderr)
merchant.cpp: In function 'void Enter()':
merchant.cpp:50:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
50 | ll mid=l+r>>1;
| ~^~
# | 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... |