이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
bool first = true;
string res = "[";
for (const auto &x : v) {
if (!first)
res += ", ";
first = false;
res += to_string(x);
}
res += "]";
return res;
}
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << to_string(H);
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
const int INF = 1e18;
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int nbSommets, nbAretes, nbItems;
cin >> nbSommets >> nbAretes >> nbItems;
vector<vector<int>> buy(nbSommets, vector<int>(nbItems));
vector<vector<int>> sell(nbSommets, vector<int>(nbItems));
for (int i = 0; i < nbSommets; ++i)
for (int j = 0; j < nbItems; ++j)
cin >> buy[i][j] >> sell[i][j];
vector<vector<int>> dis(nbSommets, vector<int>(nbSommets, INF));
for (int i = 0; i < nbSommets; ++i)
dis[i][i] = 0;
vector<tuple<int, int, int, int>> edges;
for (int iArete = 0; iArete < nbAretes; ++iArete) {
int u, v, T;
cin >> u >> v >> T;
--u, --v;
edges.emplace_back(u, v, T, 0);
dis[u][v] = T;
}
for (int k = 0; k < nbSommets; ++k)
for (int i = 0; i < nbSommets; ++i)
for (int j = 0; j < nbSommets; ++j)
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
for (int u = 0; u < nbSommets; ++u)
for (int item = 0; item < nbItems; ++item)
if (buy[u][item] != -1)
for (int v = 0; v < nbSommets; ++v)
if (sell[v][item] > buy[u][item])
edges.emplace_back(u, v, dis[u][v], buy[u][item] - sell[v][item]);
int lo = 0, up = 1e12;
while (lo < up) {
int x = (lo + up + 1) / 2;
for (int u = 0; u < nbSommets; ++u)
dis[u].assign(nbSommets, INF);
for (auto [u, v, t, l] : edges)
dis[u][v] = min(dis[u][v], x * t + l);
for (int k = 0; k < nbSommets; ++k)
for (int i = 0; i < nbSommets; ++i)
for (int j = 0; j < nbSommets; ++j)
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
bool negCycle = false;
for (int u = 0; u < nbSommets; ++u)
if (dis[u][u] <= 0)
negCycle = true;
if (negCycle)
lo = x;
else
up = x - 1;
}
cout << lo << endl;
}
# | 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... |