This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) a.size()
#define pb push_back
#define vt vector
#define s second
#define f first
#define nl '\n'
using ll = long long;
using pii = pair<int, int>;
vt<pii> dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const int N = 1e5 + 5, mod = 1e9 + 7;
const int inf = 2e9;
double eps = 1e-6;
bool fl = 0;
vt<pii> g[N], g2[N];
void slv() {
int n, m, k;
cin >> n >> m >> k;
int b[n + 1][k + 1];
int sl[n + 1][k + 1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
cin >> b[i][j] >> sl[i][j];
}
}
while (m--) {
int u, v, w;
cin >> u >> v >> w;
g[u].pb({v, w});
g2[v].pb({u, w});
}
set<pii> s;
vt<int> d1(n + 1, inf);
d1[1] = 0;
s.insert({0, 1});
while (!s.empty()) {
int u = (*s.begin()).s;
s.erase(s.begin());
for (pii to: g[u]) {
if (d1[to.f] > d1[u] + to.s) {
s.erase({d1[to.f], to.f});
d1[to.f] = d1[u] + to.s;
s.insert({d1[to.f], to.f});
}
}
}
vt<int> d2(n + 1, inf);
d2[1] = 0;
s.insert({0, 1});
while (!s.empty()) {
int u = (*s.begin()).s;
s.erase(s.begin());
for (pii to: g2[u]) {
if (d2[to.f] > d2[u] + to.s) {
s.erase({d2[to.f], to.f});
d2[to.f] = d2[u] + to.s;
s.insert({d2[to.f], to.f});
}
}
}
int ans = 0;
for (int i = 1; i <= k; i++) {
if (b[1][i] == -1) continue;
for (int j = 2; j <= n; j++) {
if (sl[j][i] <= b[1][i]) continue;
ans = max(ans, (sl[j][i] - b[1][i]) / (d1[j] + d2[j]));
}
}
cout << ans;
}
int main() {
//freopen("codes.in", "r", stdin);
//freopen("codes.out", "w", stdout);
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
int tp = 1;
if (fl) cin >> tp;
while (tp--) {
slv();
}
}
# | 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... |