이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 2e5 + 10;
const int MOD = 998244353;
#define int long long
#define ll __int128
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
ll read() { // read int128
int x; cin >> x; return (ll)x;
}
long long bm(long long b, long long p) {
if(p==0) return 1 % MOD;
long long r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
long long inv(long long b) {
return bm(b, MOD-2);
}
long long f[MAXN];
long long nCr(int n, int r) {
long long ans = f[n]; ans *= inv(f[r]); ans %= MOD;
ans *= inv(f[n-r]); ans %= MOD; return ans;
}
void precomp() {
for(int i=0; i<MAXN; i++) f[i] = (i == 0 ? 1 % MOD : (f[i-1] * i) % MOD);
}
void solve(int tc) {
int n, m, k;
cin >> n >> m >> k;
int b[n+1][k+1], s[n+1][k+1];
for(int i=1; i<=n; i++) {
for(int j=1; j<=k; j++) {
cin >> b[i][j] >> s[i][j];
}
}
int dist[n+1][n+1];
int p[n+1][n+1];
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
dist[i][j] = 1e18;
p[i][j] = 0;
if(i == j) dist[i][j] = 0;
}
}
for(int i=0; i<m; i++) {
int v, w, t;
cin >> v >> w >> t;
dist[v][w] = min(dist[v][w], t);
}
for(int qwq=1; qwq<=n; qwq++) {
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
dist[i][j] = min(dist[i][j], dist[i][qwq] + dist[qwq][j]);
}
}
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
for(int l=1; l<=k; l++) {
if(b[i][l] != -1 && s[j][l] != -1) p[i][j] = max(p[i][j], s[j][l] - b[i][l]);
}
}
}
int lb = 0, rb = 1e9;
while(lb < rb) {
int mid = (lb + rb + 1) >> 1;
double newd[n+1][n+1];
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
newd[i][j] = p[i][j] * 1.0 / mid - dist[i][j];
}
}
for(int qwq=1; qwq<=n; qwq++) {
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
newd[i][j] = max(newd[i][j], newd[i][qwq] + newd[qwq][j]);
}
}
}
bool ok = 0;
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
if(i == j) continue;
if(p[i][j] * 1.0 / mid - dist[i][j] + newd[j][i] >= 0) {
ok = 1;
}
}
}
if(ok) lb = mid;
else rb = mid - 1;
}
cout << lb << '\n';
}
int32_t main(){
precomp();
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
/*
4 5 2
10 9 5 2
6 4 20 15
9 7 10 9
-1 -1 16 11
1 2 3
2 3 3
1 4 1
4 3 1
3 1 1
*/
# | 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... |