이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//khodaya khodet komak kon
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-O2")
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 100 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000;
const ll LOG = 25;
int n, m, K, B[N][N * 10], S[N][N * 10];
ll dis[N][N], pth[N][N], D[N][N];
bool isval(ll x){
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) D[i][j] = x * dis[i][j] - pth[i][j];
for (int k = 1; k <= n; k++) for (int v = 1; v <= n; v++) for (int u = 1; u <= n; u++) if (v != u) D[v][u] = min(D[v][u], D[v][k] + D[k][u]);
for (int v = 1; v <= n; v++) for (int u = 1; u <= n; u++) if (v != u && D[v][u] + D[u][v]<= 0) return 1;
return 0;
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> K;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= 2 * K; j++){
if (j % 2 == 1) cin >> B[i][j / 2 + 1];
else cin >> S[i][j / 2];
}
}
for (int i = 0; i < N; i++)for (int j = 0; j < N; j++) dis[i][j] = INF;
for (int i = 1; i <= n; i++) dis[i][i] = 0;
for (int i = 1; i <= m; i++){
ll v, u, T;
cin >> v >> u >> T;
dis[v][u] = min(dis[v][u], T);
}
for (int k = 1; k <= n; k++)for (int v = 1; v <= n; v++) for (int u = 1; u <= n; u++) dis[v][u] = min(dis[v][u], dis[v][k] + dis[k][u]);
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++)for (int k = 1; k <= K; k++)if (S[j][k] != -1 && B[i][k] != -1) pth[i][j] = max(pth[i][j], S[j][k] - B[i][k]);
ll l = 0, r = INF;
while (r - l > 1){
ll md = (l + r) >> 1;
if (isval(md)) l = md;
else r = md;
}
cout << l;
// isval(5);
return 0;
}
# | 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... |