Submission #95774

#TimeUsernameProblemLanguageResultExecution timeMemory
95774Bodo171Travelling Merchant (APIO17_merchant)C++14
0 / 100
1071 ms43128 KiB
#include <iostream> #include <fstream> #include <queue> #include <climits> #define mp make_pair using namespace std; const int nmax=105; const int kmax=1005; queue< pair<int,int> > q; vector<int> v[nmax]; long long cost[nmax][nmax]; long long d[nmax][kmax],prof[nmax][kmax],pret[nmax][kmax]; int viz[nmax][kmax]; int n,k,m,nod,item,nxt,i,j,a,b,c; long long p,ans; bool check(long long x) { while(!q.empty()) q.pop(); q.push({0,0}); for(int i=0;i<=n;i++) for(int j=0;j<=k;j++) viz[i][j]=0; for(int i=1;i<=n;i++) for(int j=0;j<=k;j++) d[i][j]=LLONG_MIN; while(!q.empty()) { nod=q.front().first;item=q.front().second; q.pop(); if(nod==0) { for(nxt=1;nxt<=n;nxt++) if(d[nod][item]-1LL*x*cost[nod][nxt]>=d[nxt][item]) { d[nxt][item]=d[nod][item]-1LL*x*cost[nod][nxt]; q.push(mp(nxt,item)); viz[nxt][item]++; if(viz[nxt][item]>=n*(k+1)+1) return 1; } } if(item) for(int nxt=1;nxt<=n;nxt++) if(nxt!=nod&&cost[nod][nxt]<=1LL*1000*1000*1000) { if(d[nod][item]+1LL*prof[nxt][item]-1LL*x*cost[nod][nxt]>=d[nxt][0]&&prof[nxt][item]!=-1) { d[nxt][0]=d[nod][item]-1LL*x*cost[nod][nxt]+1LL*prof[nxt][item]; q.push({nxt,0}); viz[nxt][0]++; if(viz[nxt][0]>=n*(k+1)+1) return 1; } } if(!item) { for(int i=1;i<=k;i++) if(d[nod][0]-1LL*pret[nod][i]>=d[nod][i]&&pret[nod][i]!=-1) { d[nod][i]=d[nod][0]-1LL*pret[nod][i]; q.push({nod,i}); viz[nod][i]++; if(viz[nod][i]>=n*(k+1)+1) return 1; } for(nxt=1;nxt<=n;nxt++) if(nxt!=nod) if(d[nod][item]-1LL*x*cost[nod][nxt]>=d[nxt][item]) { d[nxt][item]=d[nod][item]-1LL*x*cost[nod][nxt]; q.push(mp(nxt,item)); viz[nxt][item]++; if(viz[nxt][item]>=n*(k+1)+1) return 1; } } } return 0; } int main() { //freopen("data.in","r",stdin); ios_base::sync_with_stdio(false); cin>>n>>m>>k; for(i=1;i<=n;i++) { pret[i][0]=-1,prof[i][0]=-1; for(j=1;j<=k;j++) { cin>>pret[i][j]; cin>>prof[i][j]; } } for(i=1;i<=k;i++) pret[0][i]=prof[0][i]=-1; for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(i!=j) cost[i][j]=1LL*1e16; for(i=1;i<=m;i++) { cin>>a>>b>>c; cost[a][b]=min(cost[a][b],1LL*c); } int kt; for(kt=1;kt<=n;kt++) for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(i!=kt&&j!=kt&&cost[i][kt]+cost[kt][j]<cost[i][j]) cost[i][j]=cost[i][kt]+cost[kt][j]; for(p=30;p>=0;p--) if(check(ans+(1LL<<p))) ans+=(1LL<<p); cout<<ans; 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...