이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>
using namespace std;
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;
void Hollwo_Pelw();
signed main(){
#ifndef hollwo_pelw_local
if (fopen("hollwo_pelw.inp", "r"))
assert(freopen("hollwo_pelw.inp", "r", stdin)), assert(freopen("hollwo_pelw.out", "w", stdout));
#else
using namespace chrono;
auto start = steady_clock::now();
#endif
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
int testcases = 1;
// cin >> testcases;
for (int test = 1; test <= testcases; test++){
// cout << "Case #" << test << ": ";
Hollwo_Pelw();
}
#ifdef hollwo_pelw_local
auto end = steady_clock::now();
cout << "\nExcution time : " << duration_cast<milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}
const int N = 105, K = 1005, inf = 1e9 + 7;
const long long linf = 4e18;
int n, m, k, b[N][K], s[N][K], d[N][N], c[N][N];
long long f[N][N];
void Hollwo_Pelw(){
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= k; j++)
cin >> b[i][j] >> s[i][j];
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++)
for (int _ = 1; _ <= k; _++) if (s[j][_] >= 0 && b[i][_] >= 0)
c[i][j] = max(c[i][j], s[j][_] - b[i][_]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
d[i][j] = i == j ? 0 : inf;
for (int u, v, w; m --; )
cin >> u >> v >> w, d[u][v] = w;
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
int l = 0, r = 1e9 + 7;
while (l < r) {
int m = (l + r + 1) >> 1, ok = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
f[i][j] = d[i][j] == inf || i == j ? linf : 1ll * d[i][j] * m - c[i][j];
}
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
for (int i = 1; i <= n && !ok; i++)
if (f[i][i] <= 0) ok = 1;
(ok ? l = m : r = m - 1);
}
cout << l << '\n';
}
# | 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... |