이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// In the name of God
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define _sz(e) (int)e.size()
#define _all(e) e.begin() , e.end()
#define ll long long
#define int long long
#define ld long double
#define pii pair <int , int>
#define pll pair <long long , long long>
#define piii pair <int , pair <int , int> >
#define FAST ios::sync_with_stdio(0);cin.tie(0)
#define Unique(e) e.resize(unique(_all(e)) - e.begin())
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
const int maxn = 100 + 5 , N = 10000 + 5 , SQ = 500 , base = 800287 , mod = 1e9 + 7 , INF = 1e18 + 5 , lg = 20;
const ld eps = 1e-4;
int n , m , k , mx[maxn][maxn];
int dist[maxn][maxn] , dp[maxn][maxn];
vector <pll> item[maxn] , edges[maxn];
inline bool calc(int x) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if(dist[i][j] == INF) {
dp[i][j] = -INF;
}
else {
dp[i][j] = mx[i][j] - x * dist[i][j];
}
}
}
for (int t = 0; t < n; ++t) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
dp[i][j] = max(dp[i][j] , dp[i][t] + dp[t][j]);
}
}
}
for (int i = 0; i < n; ++i) {
if(dp[i][i] >= 0) {
return 1;
}
}
return 0;
}
int32_t main() {
FAST;
cin >> n >> m >> k;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < k; ++j) {
int x , y; cin >> x >> y;
item[i].PB({x , y});
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int t = 0; t < k; ++t) {
if(item[j][t].S == -1 || item[i][t].F == -1) {
continue;
}
int val = item[j][t].S - item[i][t].F;
mx[i][j] = max(mx[i][j] , val);
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
dist[i][j] = INF;
}
}
for (int i = 0; i < m; ++i) {
int x , y , z; cin >> x >> y >> z;
x-- , y--; dist[x][y] = z;
}
for (int t = 0; t < n; ++t) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
dist[i][j] = min(dist[i][j] , dist[i][t] + dist[t][j]);
}
}
}
int s = 0 , e = 1e9 + 1;
while(s < e - 1) {
if(calc(mid)) {
s = mid;
}
else {
e = mid;
}
}
cout << s << '\n';
}
// Mistakes:
// * Read the problem carefully.
// * Check maxn.
// * Overflows.
# | 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... |