# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101122 | ae04071 | Travelling Merchant (APIO17_merchant) | C++11 | 132 ms | 3320 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |