# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101110 | ae04071 | Travelling Merchant (APIO17_merchant) | C++11 | 46 ms | 1280 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) {
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;
}
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;
}
printf("%d\n",lo+1);
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... |