제출 #1113861

#제출 시각아이디문제언어결과실행 시간메모리
1113861adkjt여행하는 상인 (APIO17_merchant)C++14
0 / 100
75 ms2640 KiB
#include<bits/stdc++.h> using namespace std; #define pii pair<long long,long long> #define f first #define s second #define ll long long //vector<pii> g[111]; ll dis[111][111],a[111][111],f[111][111]; ll buy[111][1111],sell[111][1111]; int main() { int n,m,k; cin>>n>>m>>k; for(int i=1; i<=n; i++) { for(int j=1; j<=k; j++) cin>>buy[i][j]>>sell[i][j]; for(int j=1; j<=n; j++) dis[i][j]=1e18; } for(int i=1; i<=m; i++) { int u,v,w; cin>>u>>v>>w; dis[u][v]=w; } 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++) for(int K=1; K<=n; K++) for(int j=1; j<=k; j++) { if(buy[i][j]!=-1&&sell[K][j]!=-1) a[i][K]=max(a[i][K],sell[K][j]-buy[i][j]); } ll l=0,r=1e9,ans=0; while(l<r) { ll mid=(l+r)/2; for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) f[i][j]=min((ll)1000000000000000,mid*dis[i][j])-a[i][j]; } for(int K=1; K<=n; K++) { for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { f[i][j]=min(f[i][j],f[i][K]+f[K][j]); } } } bool ch=0; for(int i=1; i<=n; i++) { if(f[i][i]<=0) { ch=1; } } if(ch) ans=mid,l=mid+1; else r=mid-1; } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...