# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
859086 | 75_yabuki | Travelling Merchant (APIO17_merchant) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _DEBU132213G
// #include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
// using namespace atcoder;
#define endl "\n"
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector<pii> vii;
const long double pi = acos(-1.0);
const int INF = 1987654321;
const ll LLINF = 2e18;
const double eps = 1e-9;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T>
auto Vector(const int n, const T& val) { return vector(n, val); }
template<typename... Ts>
auto Vector(const int n, Ts... args) { return vector(n, Vector(args...)); }
//
ll buy[104][2004];
ll sell[104][2004];
ll dist[104][104];
ll bs[104][104];
ll newdist[104][104];
struct Edge{
int u, v, weight;
bool operator<(Edge const& other){
return weight < other.weight;
}
};
int main(){
#ifdef _DEBUG
freopen ("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(NULL);
int N, M, K; cin >> N >> M >> K;
for(int i = 1; i <= N; i++){
for(int k = 1; k <= K; k++){
cin >> buy[i][k] >> sell[i][k];
}
}
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++) dist[i][j] = LLINF;
}
while(M--){
ll u, v, w; cin >> u >> v >> w;
// adj[u].push_back({v, w});
chmin(dist[u][v], w);
}
for(int k = 1; k <= N; k++){
for(int i = 1; i <= N; i++){
dist[i][i] = 0;
for(int j = 1; j <= N; j++){
chmin(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
// item
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
if(i==j) continue;
for(int k = 1; k <= K; k++){
if(sell[j][k] != -1 && buy[i][k] != -1){
chmax(bs[i][j], 1LL* sell[j][k]-buy[i][k]);
}
}
}
}
// for(int i = 1; i <= N; i++){
// for(int j = 1; j <= N; j++){
// if(dist[i][j] == LLINF) newdist[i][j] = LLINF-bs[i][j];
// else newdist[i][j] = dist[i][j] - bs[i][j];
// }
// }
// for(int i = 1; i <= N; i++){
// for(int j= 1; j <= N; j++){
// newdist[i][j] = LLINF;
// }
// }
// for(int k = 1; k <= N; k++){
// for(int i = 1; i <= N; i++){
// for(int j = 1; j <= N; j++){
// chmin(newdist[i][j], newdist[i][k] + newdist[k][j]);
// }
// }
// }
// bool flag = false;
// for(int i = 1; i <= N; i++){
// if(newdist[i][i] < 0) flag = true; break;
// }
// if(flag){
// cout << 0 << endl;
// return 0;
// }
ll lo = 0, hi = 2e9;
while(lo + 1 < hi){
ll mid = (lo + hi) / 2;
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
newdist[i][j] = LLINF;
}
}
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
if(i==j) continue;
if(dist[i][j] == LLINF) continue;
chmin(newdist[i][j], 1LL*mid*dist[i][j] - bs[i][j]);
}
}
for(int k = 1; k <= N; k++){
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
chmin(newdist[i][j], newdist[i][k] + newdist[k][j]);
}
}
}
bool flag = false;
for(int i = 1; i <= N; i++){
if(newdist[i][i] <= 0) flag = true; break;
}
if(flag) lo = mid;
else hi = mid;
}
cout << lo << endl;
return 0;
}