Submission #95782

#TimeUsernameProblemLanguageResultExecution timeMemory
95782Bodo171Travelling Merchant (APIO17_merchant)C++14
33 / 100
84 ms4088 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< int > q; vector<int> v[nmax]; long long cost[nmax][nmax],wn[nmax][nmax]; long long d[nmax],prof[nmax][kmax],pret[nmax][kmax]; int viz[nmax],inq[nmax]; int n,k,m,nod,item,nxt,i,j,a,b,c,ind; long long p,ans; bool check(long long x) { while(!q.empty()) q.pop(); q.push(0); for(int i=0;i<=n;i++) viz[i]=inq[i]=0; for(int i=1;i<=n;i++) d[i]=LLONG_MIN; while(!q.empty()) { nod=q.front();inq[nod]=0; q.pop(); for(int nxt=1;nxt<=n;nxt++) if(nxt!=nod&&cost[nod][nxt]<=1LL*1000*1000*1000) { if(d[nod]+wn[nod][nxt]-1LL*x*cost[nod][nxt]>=d[nxt]) { if(!inq[nxt]) { q.push(nxt); inq[nxt]=1; } d[nxt]=d[nod]+wn[nod][nxt]-1LL*x*cost[nod][nxt]; viz[nxt]++; if(viz[nxt]>=n) 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<=n;i++) for(j=1;j<=n;j++) for(ind=1;ind<=k;ind++) if(pret[i][ind]!=-1&&prof[j][ind]!=-1) wn[i][j]=max(wn[i][j],prof[j][ind]-pret[i][ind]); 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(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...