이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define pii pair<int, int>
#define pII pair<pii, pii>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
#define sz(x) (int)x.size()
using namespace std;
const int N = 110;
const int K = 1010;
ll dis[N][N], dis2[N][N], prf[N][N];
ll s[N][K], b[N][K];
void solve() {
int n, m, k; 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)
dis[i][j] = INF;
for (int i = 1; i <= m; ++i) {
int u, v, w; cin >> u >> v >> w;
dis[u][v] = w;
}
for (int k = 1; k <= n; ++k)
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
for (int l = 1; l <= k; ++l) {
if (s[j][l] == -1 || b[i][l] == -1) continue;
prf[i][j] = max(prf[i][j], s[j][l] - b[i][l]);
}
ll l = 0, r = 1e9;
while (l < r) {
ll mid = (l+r+1)/2;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
dis2[i][j] = mid*dis[i][j] - prf[i][j];
for (int k = 1; k <= n; ++k)
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
dis2[i][j] = min(dis2[i][j], dis2[i][k] + dis2[k][j]);
bool y = 0;
for (int i = 1; i <= n; ++i) if (dis2[i][i] <= 0) y = 1;
if (y) l = mid;
else r = mid-1;
}
cout << l << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
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... |