제출 #197967

#제출 시각아이디문제언어결과실행 시간메모리
197967stefdasca여행하는 상인 (APIO17_merchant)C++14
12 / 100
1024 ms110768 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 maxdif[102][102];

ll bst[102], bst2[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];
                }

    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 && rf[i][j] && buy[i][x] != -1 && sell[j][x] != -1)
                        maxdif[i][j] = max(maxdif[i][j], sell[j][x] - buy[i][x]);
    ll ans = 0;
    int dif = 0;
    for(int start = 1; start <= n; ++start)
    {
        int states = dif + 500000 / n;
        deque<pair<int, pair<ll, ll> > >d;
        memset(bst, 0, sizeof(bst));
        memset(bst2, 0, sizeof(bst2));
        d.pb({start, {0, 0}});
        while(!d.empty())
        {
            pair<int, pair<ll, ll> > nod = d[0];
            d.pop_front();
            if(bst[nod.fi] == 0 && nod.se.fi)
                bst[nod.fi] = nod.se.fi, bst2[nod.fi] = nod.se.se;
            else
                if(nod.se.fi * bst2[nod.fi] > nod.se.se * bst[nod.fi])
                    bst[nod.fi] = nod.se.fi, bst2[nod.fi] = nod.se.se;
                else
                    if(nod.se.se > bst2[nod.fi])
                        continue;
            --states;
            for(int vec = 1; vec <= n; ++vec)
            {
                if(rf[nod.fi][vec])
                {
                    if(vec == start)
                    {
                        ll rap = (nod.se.fi + maxdif[nod.fi][vec]) / (nod.se.se + rf[nod.fi][vec]);
                        ans = max(ans, rap);
                    }
                    else
                        d.pb({vec, {nod.se.fi + maxdif[nod.fi][vec], nod.se.se + rf[nod.fi][vec]}});
                }
            }
            if(states == 0)
                break;
        }
        dif = states;
    }
    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...