This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define loli
using namespace std;
typedef long long ll;
#define int ll
#define pii pair<int, int>
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define push emplace
#define lb(x, v) lower_bound(ALL(x), v)
#define ub(x, v) upper_bound(ALL(x), v)
#define re(x) reverse(ALL(x))
#define uni(x) x.resize(unique(ALL(x)) - x.begin())
#define inf 1000000000
#define INF 1000000000000000000
#define mod 1000000007
#define get_bit(x, y) ((x>>y)&1)
#define mkp make_pair
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
if (a.empty()) return o << "{}";
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
#ifdef loli
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif
const int mxN = 100 + 5, mxK = 1000 + 5;
int n, m, k, b[mxN][mxK], s[mxN][mxK];
vector<array<int, 3>> edge;
int dp[mxN][mxK];
int mat[mxN][mxN];
int check(int thres) {
for (int i = 1; i <= n; i++) {
dp[i][0] = 0;
for (int j = 1; j <= k; j++) {
if (b[i][j] == -1) dp[i][j] = -INF;
else dp[i][j] = -b[i][j];
}
}
// bellmen ford
for (int tms = 1; tms <= n; tms++) {
for (auto [u, v, t] : edge) {
for (int i = 0; i <= k; i++) dp[v][i] = max(dp[v][i], dp[u][i] - t * thres);
for (int i = 1; i <= k; i++) {
if (b[u][i] != -1) dp[v][i] = max(dp[v][i], dp[u][0] - t * thres - b[u][i]);
if (b[v][i] != -1) dp[v][i] = max(dp[v][i], dp[v][0] - b[v][i]);
}
for (int i = 1; i <= k; i++) {
if (s[u][i] != -1) dp[v][0] = max(dp[v][0], dp[u][i] - t * thres + s[u][i]);
}
}
}
int ans = -INF;
for (int i = 1; i <= n; i++) ans = max(ans, dp[i][0]);
return ans >= 1;
}
inline void solve() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
cin >> b[i][j] >> s[i][j];
}
}
for (int i = 0; i < m; i++) {
int u, v, t;
cin >> u >> v >> t;
edge.pb({u, v, t});
}
// binary search
int l = 0, r = 1e9 + 1;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (check(mid)) l = mid;
else r = mid - 1;
}
cout << l << '\n';
}
signed main() {
IO;
solve();
}
# | 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... |