제출 #653049

#제출 시각아이디문제언어결과실행 시간메모리
653049pauloamed여행하는 상인 (APIO17_merchant)C++14
0 / 100
76 ms2108 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];

const int INF = INT_MAX;

int sum(int a, int b){
  return a + b;
}

bool test(int r, int n){
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      if(p1[i][j] == INF){
        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], sum(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] = INF;
    }
  }

  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], sum(p1[i][l], p1[l][j]));
        }
      }
    }
  }

  int ans = 0;
  int pot = (1LL << 40);
  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...