Submission #568537

#TimeUsernameProblemLanguageResultExecution timeMemory
568537jeqchoTravelling Merchant (APIO17_merchant)C++17
100 / 100
163 ms4196 KiB
#include <bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<pair<int,int>> vpi; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define rsz resize #define sz(x) int(x.size()) #define all(x) begin(x), end(x) #define fi first #define se second int const N=1e2+3; int const K=1e3+3; ll b[N][K]; ll s[N][K]; vpi adj[N]; vi adj2[N]; int d[N][N]; ll d2[N]; ll p[N][N]; int n,m,k; int const INTX=1e9+5; vector<pair<pii,ll>>edges; int state[N]; bool cycle(int u) { if(state[u]==1)return 1; if(state[u]==2)return 0; state[u]=1; bool c=0; trav(e,adj2[u]) { c|=cycle(e); } state[u]=2; return c; } bool z() { F0R(i,n)adj2[i].clear(); fill(state,state+n,0); trav(e,edges) { if(d2[e.fi.fi]+e.se==d2[e.fi.se])adj2[e.fi.fi].pb(e.fi.se); } return cycle(0); } bool ok(int r) { edges.clear(); F0R(i,n) { F0R(j,n) { if(d[i][j]!=INTX) { edges.pb({{i,j},(ll)r*d[i][j]-p[i][j]}); } } } //cout<<"test "<<r<<'\n'; //trav(e,edges)cout<<e.fi.fi<<' '<<e.fi.se<<' '<<e.se<<'\n'; fill(d2,d2+n,2e18); d2[0]=0; F0R(i,n) { trav(e,edges) { ll cand=d2[e.fi.fi]+e.se; if(i==n-1&&cand<d2[e.fi.se]) { //cout<<"ok "<<r<<'\n'; return 1; } d2[e.fi.se]=min(d2[e.fi.se],cand); } } //cout<<"fail "<<r<<'\n'; if(z())return 1; return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m>>k; F0R(i,n) { F0R(j,k) { cin>>b[i][j]>>s[i][j]; } } F0R(i,n)fill(d[i],d[i]+n,INTX); F0R(i,m) { int v,w,t; cin>>v>>w>>t; --v;--w; adj[v].pb({w,t}); d[v][w]=t; } F0R(x,n) { F0R(i,n) { F0R(j,n) { d[i][j]=min(d[i][j],d[i][x]+d[x][j]); } } } F0R(i,n)fill(p[i],p[i]+n,0); F0R(i,n) { F0R(j,n) { F0R(u,k) { if(s[j][u]==-1||b[i][u]==-1)continue; p[i][j]=max(p[i][j],s[j][u]-b[i][u]); } } } int R=0; R0F(i,30) { if(ok(R+(1<<i))) { R+=(1<<i); } } cout<<R<<'\n'; 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...