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 god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9
// #define fisier 1
using namespace std;
typedef long long ll;
int n, m, k, buy[102][1002], sell[102][1002], rf[102][102];
int maxdif[102][102];
ll dp[102], dpaux[102];
bool viz[102];
int main()
{
#ifdef fisier
ifstream f("input.in");
ofstream g("output.out");
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> k;
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= k; ++j)
cin >> buy[i][j] >> sell[i][j];
}
for(int i = 1; i <= m; ++i)
{
int a, b, c;
cin >> a >> b >> c;
rf[a][b] = c;
}
for(int k = 1; k <= n; ++k)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
if(i != j && rf[i][k] && rf[k][j])
{
if(rf[i][j] == 0 || rf[i][j] > rf[i][k] + rf[k][j])
rf[i][j] = rf[i][k] + rf[k][j];
}
ll ans = 0;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
if(i != j && rf[i][j])
{
for(int x = 1; x <= k; ++x)
if(i != j && buy[i][x] != -1 && sell[j][x] != -1)
maxdif[i][j] = max(maxdif[i][j], sell[j][x] - buy[i][x]);
}
for(int start = 1; start <= n; ++start)
{
memset(dp, 0, sizeof(dp));
memset(dpaux, 0, sizeof(dpaux));
memset(viz, 0, sizeof(viz));
viz[start] = 1;
for(int i = 1; i <= n+1; ++i)
{
for(int j = 1; j <= n; ++j)
if(viz[j] && (j == start || rf[j][start]))
for(int k = 1; k <= n; ++k)
{
if(j != k && rf[j][k])
{
if(!viz[k] || dp[k] == 0)
dp[k] = (dp[j] + maxdif[j][k]), dpaux[k] = dpaux[j] + rf[j][k], viz[k] = 1;
else
{
double aa = (0.0000 + dp[j] + maxdif[j][k]) / (0.0000 + dpaux[j] + rf[j][k]);
double bb = (0.000 + dp[k]) / (0.0000 + dpaux[k]);
if(aa >= bb + 1e-8)
viz[k] = 1, dp[k] = (dp[j] + maxdif[j][k]), dpaux[k] = dpaux[j] + rf[j][k];
}
}
}
if(dpaux[start])
ans = max(ans, dp[start] / dpaux[start]);
}
if(dpaux[start])
ans = max(ans, dp[start] / dpaux[start]);
}
cout << ans;
return 0;
}
# | 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... |