이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <sstream>
using namespace std;
using int64 = long long;
const double EPS = 1e-9;
const int INF = (1<<30);
struct Market {
int b;
int s;
};
int N, M, K;
vector<vector<Market>> market;
vector<vector<int>> dist;
vector<vector<pair<int, int>>> edges;
bool go(int64 r) {
vector<vector<int64>> d(N, vector<int64>(N, (1LL<<60)));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (dist[i][j] != INF) {
d[i][j] = -edges[i][j].first + r * dist[i][j];
} else {
d[i][j] = (1LL<<60);
}
}
}
for (int k = 0; k < N; k++)
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
for (int i = 0; i < N; i++) {
if (d[i][i] <= 0)
return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> M >> K;
market = vector<vector<Market>>(N, vector<Market>(K));
for (int i = 0; i < N; i++) {
for (int j = 0; j < K; j++) {
cin >> market[i][j].b >> market[i][j].s;
}
}
dist = vector<vector<int>>(N, vector<int>(N, INF));
for (int i = 0; i < M; i++) {
int x, y, w;
cin >> x >> y >> w;
x--, y--;
dist[x][y] = min(dist[x][y], w);
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) {
if (i != k && k != j && j != i && dist[i][k] < INF && dist[k][j] < INF) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
}
edges = vector<vector<pair<int, int>>>(N, vector<pair<int, int>>(N, {0, 0}));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (dist[i][j] < INF) {
// i -> j
int up = 0;
for (int k = 0; k < K; k++) {
if (market[i][k].b != -1 && market[j][k].s != -1) {
up = max(up, market[j][k].s - market[i][k].b);
}
}
edges[i][j] = {up, dist[i][j]};
}
}
}
int64 l = 0, r = (1LL<<30), sol = -1;
while (l <= r) {
int64 m = (l + r) >> 1;
if (go(m)) {
sol = m;
l = m + 1;
} else {
r = m - 1;
}
}
cout << sol << "\n";
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... |