제출 #1335529

#제출 시각아이디문제언어결과실행 시간메모리
1335529iamhereforfun여행하는 상인 (APIO17_merchant)C++20
0 / 100
86 ms1252 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))
#define int long long

const int N = 1e2 + 5;
const int M = 1e6 + 5;
const int K = 301;
const int LG = 60;
const int INF = 1e18 + 5;
const int B = 1000;
const int MOD = 1e9 + 7;

int n, m, k, b[N][K], s[N][K], dis[N][N], mx[N][N], dp[N][N], gud[N][N], ans;

inline void solve()
{
    cin >> n >> m >> k;
    for (int x = 1; x <= n; x++)
    {
        for (int y = 0; y < k; y++)
        {
            cin >> b[x][y] >> s[x][y];
        }
    }
    for (int x = 1; x <= n; x++)
    {
        for (int y = 1; y <= n; y++)
        {
            dis[x][y] = INF;
            mx[x][y] = 0;
        }
    }
    for (int x = 0; x < m; x++)
    {
        int a, b, w;
        cin >> a >> b >> w;
        dis[a][b] = min(dis[a][b], w);
    }
    for (int x = 1; x <= n; x++)
    {
        for (int y = 1; y <= n; y++)
        {
            if(x == y) continue;
            for (int z = y + 1; z <= n; z++)
            {
                dis[y][z] = min(dis[y][z], dis[y][x] + dis[x][z]);
            }
            for (int z = 0; z < k; z++)
            {
                if (b[x][z] == -1 || s[y][z] == -1)
                    continue;
                mx[x][y] = max(mx[x][y], s[y][z] - b[x][z]);
            }
        }
    }
    int l = 0, r = 1e9;
    while (l <= r)
    {
        int m = (l + r) / 2;
        for (int x = 1; x <= n; x++)
        {
            for (int y = 1; y <= n; y++)
            {
                dp[x][y] = INF;
                gud[x][y] = 0;
            }
        }
        for (int x = 1; x <= n; x++)
        {
            dp[x][x] = 0;
        }
        for (int y = 1; y <= n; y++)
        {
            for (int z = 1; z <= n; z++)
            {
                if (dis[y][z] == INF)
                    continue;
                dp[y][z] = -(mx[y][z] - m * dis[y][z]);
                // cout << dp[y][z] << " " << y << " " << z << "\n";
            }
        }
        for (int x = 1; x <= n; x++)
        {
            for (int y = 1; y <= n; y++)
            {
                for (int z = 1; z <= n; z++)
                {
                    if (x == y && y == z)
                        continue;
                    dp[y][z] = min(dp[y][z], dp[y][x] + dp[x][z]);
                    if(dp[y][z] == dp[y][x] + dp[x][z]) gud[y][z] = 1;
                }
            }
        }
        bool b = 0;
        for(int x = 1; x <= n; x++)
        {
            if(gud[x][x] && dp[x][x] <= 0)
            {
                // cout << dp[x][x] << " " << m << "\n";
                b = 1;
            }
        }
        if(b)
        {
            ans = m;
            l = m + 1;
        }
        else
        {
            r = m - 1;
        }
    }
    cout << ans;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    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...