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>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
const int N=101;
const int M=1001;
const int W=1e3+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+7;
const ld EPS=1e-9;
int b[N][M],s[N][M];
ll dist[N][N],adj[N][N];
int profit[N][N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int n,m,K;
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 i=1;i<=n;i++){
for(int j=1;j<=n;j++){
dist[i][j]=INF;
}
dist[i][i]=0;
}
for(int i=1;i<=m;i++){
int u,v,w;
cin>>u>>v>>w;
dist[u][v]=w;
}
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int k=1;k<=K;k++){
if(b[i][k]==-1||s[j][k]==-1)continue;
profit[i][j]=max(profit[i][j],s[j][k]-b[i][k]);
}
}
}
int l=1,r=inf;
int ans=0;
while(l<=r){
int mid=(l+r)/2;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(dist[i][j]==INF)adj[i][j]=INF;
else adj[i][j]=dist[i][j]*1ll*mid-profit[i][j];
}
adj[i][i]=INF;
}
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
adj[i][j]=min(adj[i][j],adj[i][k]+adj[k][j]);
}
}
}
int w=0;
for(int i=1;i<=n;i++){
if(adj[i][i]<=0)w=1;
}
if(w)ans=mid,l=mid+1;
else r=mid-1;
}
cout<<ans;
}
# | 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... |