#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
typedef long long ll;
template<class T>void minimize(T& a, T b){
if(a > b){
a = b;
}
}
template<class T>void maximize(T& a, T b){
if(a < b){
a = b;
}
}
const ll INF = 1e18;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
int n, m, k;
cin >> n >> m >> k;
vector<vector<int>>buy(n + 1, vector<int>(k + 1)), sell(n + 1, vector<int>(k + 1));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= k; j++){
cin >> buy[i][j] >> sell[i][j];
}
}
auto floyd_warshall = [&] (vector<vector<ll>>& g){
for(int k = 1; k <= n; k++){
for(int u = 1; u <= n; u++){
for(int v = 1; v <= n; v++){
minimize(g[u][v], g[u][k] + g[k][v]);
}
}
}
};
vector<vector<ll>>g(n + 1, vector<ll>(n + 1, INF)), g2 = g;
for(int i = 0; i < m; i++){
int u, v;
cin >> u >> v >> g[u][v];
}
floyd_warshall(g);
vector<vector<int>>profit(n + 1, vector<int>(n + 1, 0));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
for(int t = 1; t <= k; t++){
if(buy[i][t] != -1 && sell[j][t] != -1){
maximize(profit[i][j], sell[j][t] - buy[i][t]);
}
}
}
}
int low = 1, high = 1e9, ans = 0;
while(low <= high){
int mid = (low + high) >> 1;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
g2[i][j] = ll(mid) * min(g[i][j], INF / mid) - profit[i][j];
}
}
floyd_warshall(g2);
bool flag = false;
for(int i = 1; i <= n; i++){
if(g2[i][i] < 1){
flag = true;
break;
}
}
if(flag){
low = (ans = mid) + 1;
}
else{
high = mid - 1;
}
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp: In function 'int main()':
merchant.cpp:19:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |