Submission #95777

#TimeUsernameProblemLanguageResultExecution timeMemory
95777Bodo171Travelling Merchant (APIO17_merchant)C++14
0 / 100
1074 ms3796 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]; vector<long long> cost[nmax]; bool inq[nmax][kmax]; 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,inq[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();inq[nod][item]=0; viz[nod][item]++; for(int i=0;i<v[nod].size();i++) { if(d[nod][item]-1LL*x*cost[nod][i]>=d[v[nod][i]][item]) { d[v[nod][i]][item]=d[nod][item]-1LL*x*cost[nod][i]; if(!inq[v[nod][i]][item]) { inq[v[nod][i]][item]=1; q.push(mp(v[nod][i],item)); } viz[v[nod][i]][item]++; if(viz[v[nod][i]][item]>=n*(k+1)+1) return 1; } nxt=v[nod][i]; if(item) { if(d[nod][item]+1LL*prof[nxt][item]-1LL*x*cost[nod][i]>=d[nxt][0]&&prof[nxt][item]!=-1) { d[nxt][0]=d[nod][item]-1LL*x*cost[nod][i]+1LL*prof[nxt][item]; if(!inq[nxt][0]) { inq[nxt][0]=1; 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]; if(!inq[nod][i]) { inq[nod][i]=1; q.push({nod,i}); } viz[nod][i]++; if(viz[nod][i]>=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<=n;i++) v[0].push_back(i),cost[0].push_back(0); for(i=1;i<=k;i++) pret[0][i]=prof[0][i]=-1; for(i=1;i<=m;i++) { cin>>a>>b>>c; v[a].push_back(b); cost[a].push_back(c); } for(p=29;p>=0;p--) if(check(ans+(1LL<<p))) ans+=(1LL<<p); cout<<ans; return 0; }

Compilation message (stderr)

merchant.cpp: In function 'bool check(long long int)':
merchant.cpp:32:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<v[nod].size();i++)
                     ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...