제출 #487579

#제출 시각아이디문제언어결과실행 시간메모리
487579leaked여행하는 상인 (APIO17_merchant)C++14
12 / 100
46 ms1448 KiB
#include <bits/stdc++.h> #define f first #define s second #define vec vector #define pb push_back #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define pw(x) (1LL<<(x)) #define sz(x) (int)(x).size() #define fast_iati ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);} template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);} typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll>pll; const int N=101; const int K=1001; const ll inf=1e18; int b[N][K],s[N][K]; ll dst[N][N]; int mx[N][N]; vec<pii> g[N]; signed main(){ fast_iati; int n,m,k; 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++){ for(int j=0;j<n;j++){ if(i==j ) continue; for(int t=0;t<k;t++){ if(b[i][t]==-1 || s[j][t]==-1) continue; umax(mx[i][j],-b[i][t]+s[j][t]); } } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++) dst[i][j]=inf; dst[i][i]=0; } for(int i=0;i<m;i++){ int v,u,w; cin>>v>>u>>w;--v;--u; umin(dst[v][u],(ll)w); } for(int t=0;t<n;t++){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ umin(dst[i][j],dst[i][t]+dst[t][j]); } } } auto check=[&](ll x){ vec<ll> dp(n,-inf); priority_queue<pll>pq; for(int j=1;j<n;j++){ if(dst[0][j]<=inf/x && umax(dp[j],mx[0][j]-1ll*x*dst[0][j])) pq.push({dp[j],j}); } vec<ll>popped(n,0); while(!pq.empty()){ if(dp[0]>=0) return 1; auto v=pq.top(); pq.pop(); ll r=v.f;int u=v.s; if(r!=dp[u]) continue; popped[u]=1; for(int j=0;j<n;j++){ if(dst[u][j]<=inf/x && umax(dp[j],dp[u]+mx[u][j]-1ll*x*dst[u][j])){ pq.push({dp[j],j}); if(popped[j]) return 1; } } } return 0; }; // cout<<check(3); // return 0; ll l=1,r=inf; while(l!=r){ ll mid=(l+r)/2; if(check(mid)) l=mid+1; else r=mid; } cout<<l-1; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...