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 ll long long
#define pb push_back
#define task "262144"
#define pll pair<ll, ll>
#define pi pair<pll, pll>
#define fi first
#define se second
using namespace std;
const ll mod = 1e16;
const ll N = 1e2+5;
const int base = 313;
ll n, m, t, k, T, ans, tong, a[N], c[N][N], dp[N][N], b[N][N*10], s[N][N*10], w[N][N];
vector<ll> adj[N];
vector<ll> kq;
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
bool check(ll x)
{
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= n; j ++)
{
dp[i][j] = c[i][j] - min(w[i][j], mod/x) * x;
}
}
for(int p = 1; p <= n; p ++)
{
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= n; j ++)
{
dp[i][j] = min(mod,max(dp[i][j], dp[i][p] + dp[p][j]));
}
}
}
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= n; j ++)
{
if(i == j || dp[i][j] == -mod || dp[j][i] == -mod)continue;
if(dp[i][j] + dp[j][i] >= 0)return true;
}
}
return false;
}
void sol()
{
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 j = 1; j <= n; j ++)
{
if(i == j)continue;
w[i][j] = mod;
}
}
while(m -- > 0)
{
ll x, y;
cin >> x >> y;
cin >> w[x][y];
}
for(int p = 1; p <= n; p ++)
{
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= n; j ++)
{
w[i][j] = min(w[i][j], w[i][p]+w[p][j]);
}
for(int j = 1; j <= k; j ++)
{
if(s[p][j] == -1 || b[i][j] == -1)continue;
c[i][p] = max(c[i][p], s[p][j]-b[i][j]);
}
}
}
//for(int i = 1; i <= n; i ++)for(int j = 1; j <= n; j ++)cout << w[i][j] << " " << c[i][j] << '\n';
ll lf = 1, rt = mod, mid;
while(lf <= rt)
{
mid = (lf + rt) / 2;
if(check(mid))lf = mid + 1;
else rt = mid - 1;
}
cout << rt;
}
int main()
{
if(fopen(task".in", "r"))
{
freopen(task".in", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
/*
4 5 2
10 9 5 2
6 4 20 15
9 7 10 9
-1 -1 16 11
1 2 3
2 3 3
1 4 1
4 3 1
3 1 1
*/
Compilation message (stderr)
merchant.cpp: In function 'int main()':
merchant.cpp:103:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
103 | freopen(task".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:104:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |