Submission #653030

#TimeUsernameProblemLanguageResultExecution timeMemory
653030pauloamedTravelling Merchant (APIO17_merchant)C++14
0 / 100
68 ms3368 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int MAXN = 101;
const int MAXK = 1001;

int sell[MAXN][MAXK];
int buy[MAXN][MAXK];

int p1[MAXN][MAXN];
int best[MAXN][MAXN];

int p2[MAXN][MAXN];

bool test(int r, int n){
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      if(p1[i][j] == INT_MAX){
        p2[i][j] = 0;
      }else{
        p2[i][j] = best[i][j] - r * p1[i][j];
        // cout << i << " " << j << " : ";
        // cout << best[i][j] << " " << p1[i][j] << " : ";
        // cout << p2[i][j] << "\n"; 
      }
    }
  }

  for(int k = 0; k < n; k++){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        p2[i][j] = max(p2[i][j], p2[i][k] + p2[k][j]);
      }
    }
  }

  for(int i = 0; i < n; ++i){
    // cout << r << " : " << i << " : " << p2[i][i] << endl;
    if(p2[i][i] >= 0) return true;
  }
  return false;
}

int32_t main(){
  cin.tie(NULL)->sync_with_stdio(false);
  int n, m, k; cin >> n >> m >> k;
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < k; ++j){
      int ki = j / 2;
      cin >> buy[i][ki];
      cin >> sell[i][ki];
    }
  }

  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      p1[i][j] = INT_MAX;
    }
  }

  for(int i = 0; i < m; ++i){
    int a, b, c; cin >> a >> b >> c;
    a--; b--;
    p1[a][b] = c;
  }


  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      for(int l = 0; l < k; ++l){
        if(buy[i][l] > -1 && sell[j][l] > -1){
          int prof = sell[j][l] - buy[i][l];
          best[i][j] = max(prof, best[i][j]);
        }
      }
    }
  }

  {
    for(int l = 0; l < n; l++){
      for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
          p1[i][j] = min(p1[i][j], p1[i][l] + p1[l][j]);
        }
      }
    }
  }

  int ans = 0;
  int pot = (1LL << 30);
  while(pot){
    int mans = ans + pot;
    if(test(mans, n)) ans = mans;
    pot /= 2;
  }
  cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...