Submission #197957

#TimeUsernameProblemLanguageResultExecution timeMemory
197957stefdascaTravelling Merchant (APIO17_merchant)C++14
0 / 100
1064 ms13388 KiB
#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 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];
                }
    int ans = 0;
    for(int start = 1; start <= n; ++start)
    {
        int states = 1000000 / (n * k);
        deque<pair<int, pair<int, int> > >d;
        d.pb({start, {0, 0}});
        while(!d.empty())
        {
            --states;
            pair<int, pair<int, int> > nod = d[0];
         //   cout << nod.fi << " " << nod.se.fi << " " << nod.se.se << '\n';
            d.pop_front();
            for(int vec = 1; vec <= n; ++vec)
            {
                if(vec != nod.fi && rf[nod.fi][vec])
                {
                    for(int j = 1; j <= k; ++j)
                        if(buy[nod.fi][j] != -1 && sell[vec][j] != -1 && buy[nod.fi][j] < sell[vec][j])
                        {
                            if(vec == start)
                            {
                               // cout << nod.fi << " " << vec << " " << (nod.se.fi + sell[vec][j] - buy[nod.fi][j]) << " " << (nod.se.se + rf[nod.fi][vec]) << '\n';
                                ans = max(ans, (nod.se.fi + sell[vec][j] - buy[nod.fi][j]) / (nod.se.se + rf[nod.fi][vec]));
                            }
                            else
                                d.pb({vec, {nod.se.fi + sell[vec][j] - buy[nod.fi][j], nod.se.se + rf[nod.fi][vec]}});
                        }
                    if(vec == start)
                    {
                       // cout << nod.fi << " " << vec << " " << (nod.se.fi) << " " << (nod.se.se + rf[nod.fi][vec]) << '\n';
                        ans = max(ans, (nod.se.fi) / (nod.se.se + rf[nod.fi][vec]));
                    }
                    else
                        d.pb({vec, {nod.se.fi, nod.se.se + rf[nod.fi][vec]}});
                }
            }
            if(states == 0)
                break;
        }
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...