Submission #101122

#TimeUsernameProblemLanguageResultExecution timeMemory
101122ae04071Travelling Merchant (APIO17_merchant)C++11
100 / 100
132 ms3320 KiB
#include <bits/stdc++.h> using namespace std; using lli=long long; int n,m,k; lli adj[101][101], car[101][101], dist[100]; int s[100][1000],b[100][1000]; bool check(int C, int f=-1) { if(f==-1)fill(dist, dist+n, 0); else fill(dist,dist+n,1000000000000000ll), dist[f]=0; for(int t=0;t<n;t++) { int chg=0; for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(adj[i][j]) { if(dist[j] > dist[i] + C*adj[i][j] - car[i][j]) { chg=1; dist[j] = dist[i] + C*adj[i][j] - car[i][j]; } } if(!chg) break; if(t==n-1) return true; } if(f!=-1) { for(int i=0;i<n;i++) if(adj[i][f] && dist[i] + C*adj[i][f] - car[i][f] ==0) return true; return false; } else return false; } int main() { scanf("%d%d%d",&n,&m,&k); for(int i=0;i<n;i++) { for(int j=0;j<k;j++) scanf("%d%d",&b[i][j], &s[i][j]); } for(int i=0;i<m;i++) { int a,b; lli c; scanf("%d%d%lld",&a,&b,&c); a--;b--; adj[a][b] = c; } for(int k=0;k<n;k++) for(int i=0;i<n;i++) for(int j=0;j<n;j++) { if(adj[i][k] && adj[k][j] && (!adj[i][j] || adj[i][j] > adj[i][k]+adj[k][j])) { adj[i][j] = adj[i][k]+adj[k][j]; } } for(int i=0;i<n;i++)for(int j=0;j<n;j++) if(adj[i][j]) { int ad=0; for(int t=0;t<k;t++) if(s[j][t]!=-1 && b[i][t]!=-1) { ad=max(ad,s[j][t]-b[i][t]); } car[i][j] = ad; } int lo=-1,up=1000000000; while(up-lo>1) { int md=(lo+up)>>1; if(check(md)) lo=md; else up=md; } for(int i=0;i<n;i++) { if(check(lo+1, i)) { lo++; break; } } printf("%d\n",lo); return 0; }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&m,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~~
merchant.cpp:32:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         for(int j=0;j<k;j++) scanf("%d%d",&b[i][j], &s[i][j]);
                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%lld",&a,&b,&c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...