Submission #1043795

#TimeUsernameProblemLanguageResultExecution timeMemory
1043795fauzCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
166 ms32076 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;

const int MAXN = 200005;

typedef pair<int, int> II;

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

void dijk(int a, int b)
{
    fill(d + 1, d + n + 1, LLONG_MAX);
    q.clear();
    q.insert(II(0, a));
    d[a] = 0;

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

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

bool clear[MAXN];

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

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

    dijk(s, t);

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

    fill(clear + 1, clear + n + 1, false);

    while (!T.empty())
    {
        int i = T.back();
        T.pop_back();
        if (clear[i])
            continue;
        clear[i] = true;
        for (II node : prv[i])
        {
            w[node.se] = 0;
            T.push_back(node.fi);
        }
    }

    dijk(u, v);

    cout << d[v];
}

Compilation message (stderr)

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