제출 #976653

#제출 시각아이디문제언어결과실행 시간메모리
976653phcbakaRelay Marathon (NOI20_relaymarathon)C++17
17 / 100
160 ms7588 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
using ii = pair <int, int>;

int n, m, k;


void read()
{
    cin >> n >> m >> k;
}

struct vet
{
    bool spec[511] = {false};
    int a[511][511];
    ii dp[511][511];

    void calc()
    {
        memset(a, 0x3f3f, sizeof(a));
        for (int i = 1; i <= n; ++i) a[i][i] = 0;

        for (int i = 1; i <= m; ++i)
        {
            int u, v, L;
            cin >> u >> v >> L;
            a[u][v] = min(a[u][v], L);
            a[v][u] = min(a[v][u], L);
        }

        for (int i = 1; i <= k; ++i)
        {
            int u;
            cin >> u;
            spec[u] = 1;
        }

        for (int k = 1; k <= n; ++k)
            for (int i = 1; i <= n; ++i)
                for (int j = 1; j <= n; ++j)
                    a[i][j] = min(a[i][j], a[i][k]+a[k][j]);

        for (int i = 1; i <= n; ++i)
        {
            for (int j = 1; j <= n; ++j)
                if (spec[i] == 0 or spec[j] == 0 or i == j)
                {
                    dp[i][j] = ii(1e9, j);
                }
                else dp[i][j] = ii(a[i][j], j);

            sort (dp[i]+1, dp[i]+n+1);
        }

        int ans = LLONG_MAX;

        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j)
                for (int t = 1; t <= min(5ll, n); ++t)
                    for (int c = 1; c <= min(5ll, n); ++c)
                        if (i != j and i != dp[i][t].second and i != dp[j][c].second
                            and j != dp[i][t].second and j != dp[j][c].second
                            and dp[i][t].second != dp[j][c].second)
                        {
                            ans = min(ans, dp[i][t].first + dp[j][c].first);
                        }

        cout << ans;
        exit(0);
    }
}Vetcan;

signed main()
{
    cin.tie(0)->sync_with_stdio(0);

    #define task "cities"
    if (fopen(task ".inp", "r"))
    {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }

    read ();

    if (n <= 500)
    {
        Vetcan.calc();
    }

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

RelayMarathon.cpp: In function 'int main()':
RelayMarathon.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
RelayMarathon.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...