Submission #20357612


Source Code Expand

#include <bits/stdc++.h>
#define ll long long
#define pli pair<ll,int>
#define f first
#define s second
using namespace std;

const int maxn = 1e5+1;
const ll INF = 1e18;
int n,m,x;
vector<array<int,3>> edges[maxn];
ll dist[maxn],y;

void dijkstra(int src)
{
    priority_queue<pli,vector<pli>,greater<pli>> q;
    for (int i=1;i<=n;++i)
        dist[i]=INF;
    q.push({0,src});
    dist[src]=0;
    while (!q.empty())
    {
        y=q.top().f;
        x=q.top().s;
        q.pop();
        if (dist[x]<y)
            continue;
        for (auto i : edges[x])
            if (((y+i[2]-1)/i[2])*i[2]+i[1]<dist[i[0]])
            {
                dist[i[0]]=((y+i[2]-1)/i[2])*i[2]+i[1];
                q.push({dist[i[0]],i[0]});
            }
    }
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    int a,b,c,d,from,to;
    cin>>from>>to;
    while (m--)
    {
        cin>>a>>b>>c>>d;
        edges[a].push_back({b,c,d});
        edges[b].push_back({a,c,d});
    }
    dijkstra(from);
    if (dist[to]==INF)
        dist[to]=-1;
    cout<<dist[to];
    return 0;
}

Submission Info

Submission Time
Task E - Train
User ScarletS
Language C++ (GCC 9.2.1)
Score 500
Code Size 1154 Byte
Status AC
Exec Time 77 ms
Memory 11416 KiB

Judge Result

Set Name Sample All after_contest
Score / Max Score 0 / 0 500 / 500 0 / 0
Status
AC × 4
AC × 28
AC × 3
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All hand.txt, max_01.txt, random_01.txt, random_02.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
after_contest after_contest_01.txt, after_contest_02.txt, after_contest_03.txt
Case Name Status Exec Time Memory
after_contest_01.txt AC 10 ms 5972 KiB
after_contest_02.txt AC 60 ms 11284 KiB
after_contest_03.txt AC 57 ms 11416 KiB
hand.txt AC 8 ms 5832 KiB
max_01.txt AC 71 ms 9828 KiB
random_01.txt AC 65 ms 10588 KiB
random_02.txt AC 45 ms 9300 KiB
random_05.txt AC 31 ms 7796 KiB
random_06.txt AC 35 ms 7736 KiB
random_07.txt AC 41 ms 9404 KiB
random_08.txt AC 39 ms 9488 KiB
random_11.txt AC 34 ms 7508 KiB
random_12.txt AC 31 ms 7848 KiB
random_13.txt AC 31 ms 7548 KiB
random_14.txt AC 34 ms 8088 KiB
random_15.txt AC 41 ms 8824 KiB
random_16.txt AC 36 ms 7888 KiB
random_17.txt AC 41 ms 9360 KiB
random_18.txt AC 26 ms 7672 KiB
random_21.txt AC 72 ms 9836 KiB
random_22.txt AC 65 ms 9836 KiB
random_23.txt AC 62 ms 9708 KiB
random_24.txt AC 61 ms 9800 KiB
random_31.txt AC 77 ms 10824 KiB
random_32.txt AC 74 ms 10772 KiB
random_33.txt AC 72 ms 10800 KiB
random_34.txt AC 74 ms 10792 KiB
sample_01.txt AC 5 ms 5940 KiB
sample_02.txt AC 6 ms 5824 KiB
sample_03.txt AC 7 ms 5832 KiB
sample_04.txt AC 6 ms 5928 KiB