제출 #1226341

#제출 시각아이디문제언어결과실행 시간메모리
1226341kunzaZa183여행하는 상인 (APIO17_merchant)C++20
12 / 100
65 ms1092 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> status(n, vector<int>(2 * k));
  for (auto &a : status) {
    for (auto &b : a)
      cin >> b;
  }

  const int bign = 1e9;
  vector<vector<int>> adjmat(n, vector<int>(n, bign));
  for (int i = 0; i < m; i++) {
    int a, b, t;
    cin >> a >> b >> t;
    a--, b--;
    adjmat[a][b] = t;
  }
  for (int i = 0; i < n; i++)
    adjmat[i][i] = 0;

  for (int rounds = 0; rounds < 6; rounds++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++)
          adjmat[i][j] = min(adjmat[i][j], adjmat[i][k] + adjmat[k][j]);

  struct frac {
    ll a, b;
    bool operator<(frac x) const { return a * x.b < b * x.a; }
    frac operator+(frac x) { return {a + x.a, b + x.b}; }
  };

  vector<vector<int>> maxp(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int in = 0; in < k; in++) {
        if (status[i][in * 2] != -1 && status[j][in * 2 + 1] != -1)
          maxp[i][j] =
              max(maxp[i][j], status[j][in * 2 + 1] - status[i][in * 2]);
      }
    }
  }

  // for (auto a : adjmat) {
  //   for (auto b : a)
  //     cout << b << " ";
  //   cout << "\n";
  // }
  //
  // for (auto a : maxp) {
  //   for (auto b : a)
  //     cout << b << " ";
  //   cout << "\n";
  // }

  frac ans = {0, 1};
  for (int i = 0; i < 1; i++) {
    vector<frac> vf(n, {0, bign});

    for (int j = 0; j < n; j++)
      vf[j] = {maxp[i][j], adjmat[i][j]};

    for (int rounds = 0; rounds < n; rounds++) {
      for (int st = 0; st < n; st++) {
        for (int ed = 0; ed < n; ed++) {
          vf[ed] = max(vf[ed], vf[st] + frac({maxp[st][ed], adjmat[st][ed]}));
        }
      }
      // cout << "ROUND: " << i << " " << rounds << "\n";
      // for (auto a : vf)
      //   cout << a.a << "," << a.b << " ";
      // cout << "\n";
    }

    // cout << "\n";
    for (int j = 0; j < n; j++) {
      auto tmp = vf[j] + frac({maxp[j][i], adjmat[j][i]});
      // cout << tmp.a << "," << tmp.b << " ";
      ans = max(ans, tmp);
    }
    // cout << "\n\n";
  }

  cout << ans.a / ans.b << "\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...