Submission #916096

# Submission time Handle Problem Language Result Execution time Memory
916096 2024-01-25T09:33:09 Z bmh123456789asdf Commuter Pass (JOI18_commuter_pass) C++14
0 / 100
101 ms 19564 KB
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
const int N = 1e5 + 1;
const int oo = 1e18;
int n, m, S, T, U, V;
int c[N], w[N];
vector<pair<int,int>> adj[N];


struct mmb
{
    int vertex, dlab;
    bool operator < (const mmb& other) const
    {
        return dlab > other.dlab;
    }
};
priority_queue<mmb> Q;



void DFS(int u,int par)
{
    for(auto v : adj[u])
    {
        if(c[v.fi] + w[v.se] == c[u] && v.fi != par)
        {
            w[v.se] = 0;
            DFS(v.fi, u);
        }
    }
}

void dijikstra1()
{
    fill(c + 1, c + n + 1, oo);
    c[S] = 0;
    Q.push({S, 0});
    while(!Q.empty())
    {
        auto o = Q.top(); Q.pop();
        int u = o.vertex;
        if(c[u] != o.dlab || u == T) continue;
        for(auto v : adj[u])
        {
            if(c[u] + w[v.se] < c[v.fi])
            {
                c[v.fi] = c[u] + w[v.se];
                Q.push({v.fi, c[v.fi]});
            }
        }
    }
    DFS(T, 0);

}

void dijikstra2()
{
    while(!Q.empty()) Q.pop();
    fill(c + 1, c + n + 1, oo);
    c[U] = 0;
    Q.push({U, 0});
    while(!Q.empty())
    {
        auto o = Q.top(); Q.pop();
        int u = o.vertex;
        if(c[u] != o.dlab) continue;
        if(u == V) break;
        for(auto v : adj[u])
        {
            if(c[u] + w[v.se] < c[v.fi])
            {
                c[v.fi] = c[u] + w[v.se];
                Q.push({v.fi, c[v.fi]});
            }
        }
    }

}


int32_t main()
{
//    freopen("test.inp", "r" ,stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;
    cin >> S >> T >> U >> V;

    for(int i = 1; i <= m; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        adj[x].push_back({y, i});
        adj[y].push_back({x, i});
        w[i] = z;
    }

    dijikstra1();
    dijikstra2();
    cout << c[V];
}
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 19564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 101 ms 19480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4696 KB Output is correct
2 Correct 1 ms 2796 KB Output is correct
3 Incorrect 1 ms 2652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 19564 KB Output isn't correct
2 Halted 0 ms 0 KB -