제출 #487944

#제출 시각아이디문제언어결과실행 시간메모리
487944Mahdi여행하는 상인 (APIO17_merchant)C++17
12 / 100
62 ms2584 KiB
#include<bits/stdc++.h> #pragma GCC optimize ("Ofast") using namespace std; #define all(v) v.begin(), v.end() #define pii pair<int, int> #define pil pair<int, ll> #define pll pair<ll, ll> #define F first #define S second typedef long long ll; const int N=105, K=1e3+5; int n, m, k, b[N][K], s[N][K], dis[N][N], a[N][N]; bool c[N][N]; ll d[N][N], ds[N][N]; bool ok(ll x){ for(int i=0;i<n;++i){ for(int j=0;j<n;++j) ds[i][j]=d[i][j]=-x*dis[i][j]+a[i][j]; } for(int o=0;o<n;++o){ for(int i=0;i<n;++i){ if(d[i][i]>0) return 1; } for(int i=0;i<n;++i){ for(int j=0;j<n;++j){ if(c[i][o] && c[o][j]) ds[i][j]=max(ds[i][j], d[i][o]+d[o][j]); } } for(int i=0;i<n;++i){ for(int j=0;j<n;++j) d[i][j]=ds[i][j]; } } for(int i=0;i<n;++i){ for(int j=0;j<i;++j){ if(c[i][j] && c[j][i] && d[i][j]+d[j][i]>=0) return 1; } for(int j=i+1;j<n;++j){ if(c[i][j] && c[j][i] && d[i][j]+d[j][i]>=0) return 1; } } return 0; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m>>k; for(int i=0;i<n;++i){ for(int j=0;j<k;++j) cin>>b[i][j]>>s[i][j]; } for(int i=0;i<n;++i){ fill(dis[i], dis[i]+n, 1e9+5); dis[i][i]=0; } int u, v, w; for(int i=0;i<m;++i){ cin>>u>>v>>w; dis[--u][--v]=w; } for(int o=0;o<n;++o){ for(int i=0;i<n;++i){ for(int j=0;j<n;++j) dis[i][j]=min(dis[i][j], dis[i][o]+dis[o][j]); } } for(int i=0;i<n;++i){ for(int j=0;j<n;++j){ if(dis[i][j]==5+1e9){ c[i][j]=0; dis[i][j]=0; } else c[i][j]=1; } } for(int i=0;i<n;++i){ for(int j=0;j<n;++j){ for(int o=0;o<k;++o){ if(b[i][o]!=-1 && s[j][o]!=-1) a[i][j]=max(a[i][j], s[j][o]-b[i][o]); } } } int l=0, r=5e8; while(l<r-1){ int mid=(l+r)/2; if(ok(mid)) l=mid; else r=mid; } cout<<l; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...