이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const ll inf = 4e9;
const ll INF = LONG_LONG_MAX / 2;
const int mod = 1e9+7;
const int maxn = 100 + 1;
ll c[maxn][maxn];
ll dp[maxn][maxn];
void solve() {
int n, m, k;
cin >> n >> m >> k;
ll b[n][k], s[n][k];
ll a[n][n];
vt<pii> g[n];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++)a[i][j] = INF;
for(int j = 0; j < k; j++){
cin >> b[i][j] >> s[i][j];
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
for(int o = 0; o < k; o++){
if(b[i][o] != -1)c[i][j] = max(c[i][j], s[j][o] - b[i][o]);
}
}
}
for(int i = 0, u, v, d; i < m; i++){
cin >> u >> v >> d;
--u, --v;
g[u].pb({v, d});
}
for(int i = 0; i < n; i++){
priority_queue<pii, vt<pii>, greater<pii>> pq;
pq.push({0, i});
a[i][i] = 0;
while(!pq.empty()){
pii nw = pq.top();
pq.pop();
if(a[i][nw.ss] != nw.ff)continue;
for(auto j : g[nw.ss]){
if(a[i][j.ff] > nw.ff + j.ss){
a[i][j.ff] = nw.ff + j.ss;
pq.push({a[i][j.ff], j.ff});
}
}
}
}
ll l = 0, r = 1000000001;
while(l + 1 < r){
ll mid = l + (r - l) / 2;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i != j)dp[i][j] = c[i][j] - min(a[i][j], INF / mid) * mid;
else dp[i][i] = -INF;
}
}
bool ok = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
for(int o = 0; o < n; o++){
if(dp[j][o] <= dp[j][i] + dp[i][o])dp[j][o] = dp[j][i] + dp[i][o];
}
}
}
for(int i = 0; i < n; i++){
if(dp[i][i] >= 0)ok = 1;
}
if(ok)l = mid;
else r = mid;
}
cout << l;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int times = 1;
//cin >> times;
for(int i = 1; i <= times; i++) {
solve();
}
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... |