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>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
#define sz(x) (int)x.size()
#define ff first
#define se second
#define mp make_pair
using ll = long long;
int mod = (ll)1e9 + 7;
const int INF = 1e9 + 1;
const int N = 2e5 + 100;
const double eps = 1e-7;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template<class T, size_t SZ> using AR = array<T, SZ>;
template<class T> using PR = pair<T, T>;
template <typename XPAX>
bool ckma(XPAX &x, XPAX y) {
return (x < y ? x = y, 1 : 0);
}
template <typename XPAX>
bool ckmi(XPAX &x, XPAX y) {
return (x > y ? x = y, 1 : 0);
}
const ll inf = (ll)1e17;
ll dis[101][101];
V<PR<int>> g[101];
int n, m, k;
void calc_dis(int x) {
priority_queue<pair<ll,int>> q;
q.push({0, x});
forn(i, n)dis[x][i] = inf;
dis[x][x] = 0;
while(sz(q)) {
auto [s, v] = q.top();
s = -s;
q.pop();
if(s != dis[x][v])continue;
for(auto [c,w] : g[v]) {
if(s + w < dis[x][c]) {
dis[x][c] = s+w;
q.push({-dis[x][c], c});
}
}
}
}
void solve() {
cin >> n >> m >> k;
VV<int> b(n,V<int>(k));
auto s =b;
forn(i, n) forn(j, k) {
cin >> b[i][j] >> s[i][j];
}
forn(i, m) {
int a, b, c;
cin >> a >> b >> c;
--a;--b;
g[a].emplace_back(b,c);
}
forn(i, n) calc_dis(i);
ll ret = 0;
for(int i = 1;i < n;++i) for(int j = 0;j < k;++j) {
if(b[0][j] == -1 || s[i][j] == -1)continue;
ckma(ret, 1ll*(s[i][j]-b[0][j])/(dis[0][i]+dis[i][0]));
}
cout << ret << '\n';
}
void test_case() {
int t;
cin >> t;
forn(p, t) {
//cout << "Case #" << p + 1 << ": ";
solve();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
}
# | 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... |