제출 #1052790

#제출 시각아이디문제언어결과실행 시간메모리
1052790fauzCommuter Pass (JOI18_commuter_pass)C++14
24 / 100
156 ms41328 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;

const int MAXN = 1001;

typedef pair<int, int> II;

int n, m, s, t, u, v;
long long d[MAXN][MAXN];
vector<II> g[MAXN];
set<II> q;

void dijk(int a)
{
    q.insert(II(0, a));
    d[a][a] = 0;

    while (!q.empty())
    {
        int x = q.begin()->se;
        q.erase(q.begin());

        for (II node : g[x])
        {
            int y = node.fi, w = node.se;
            if (d[a][y] > d[a][x] + w)
            {
                if (d[a][y] < LLONG_MAX)
                    q.erase(II(d[a][y], y));
                d[a][y] = d[a][x] + w;
                q.insert(II(d[a][y], y));
            }
        }
    }
}

bool clear[MAXN];

int32_t main()
{
    if (fopen("inp.txt", "r"))
    {
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }

    cin >> n >> m >> s >> t >> u >> v;
    for (int i = 1; i <= m; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;
        g[a].push_back(II(b, c));
        g[b].push_back(II(a, c));
    }

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            d[i][j] = LLONG_MAX;

    vector<int> T;
    T.push_back(t);

    for (int i = 1; i <= n; ++i)
        dijk(i);

    long long ans = d[u][v];
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            for (int k = 1; k <= n; ++k)
                if (d[s][t] == d[s][k] + d[k][i] + d[i][t] && d[s][t] == d[s][k] + d[k][j] + d[j][t])
                    ans = min(ans, d[u][i] + d[j][v] + min(d[k][i], d[k][j]));
    cout << ans;
}

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

commuter_pass.cpp: In function 'int32_t main()':
commuter_pass.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         freopen("inp.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         freopen("out.txt", "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...