Submission #983859

#TimeUsernameProblemLanguageResultExecution timeMemory
983859vjudge1Robot (JOI21_ho_t4)C++17
0 / 100
355 ms42040 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define print(a) for(auto x : a) cout << x << ' '; cout << endl;

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<array<int, 3>> graph[n + 1];
    map<int, int> p[n + 1];
    for(int i = 0; i < m; i ++){
        int a, b, c, P;
        cin >> a >> b >> c >> P;
        graph[a].push_back({b, c, P});
        graph[b].push_back({a, c, P});
        p[a][c] += P;
        p[b][c] += P;
    }
    vector<int> mins(n + 1, 1e18);
    set<array<int, 2>> s;
    s.insert({0, 1});
    mins[1] = 0;
    while(!s.empty()){
        array<int, 2> x = *s.begin();
        s.erase(s.begin());

        for(auto y : graph[x[1]]){
            if(mins[y[0]] > x[0] + (p[x[1]][y[1]] > 1 ? 1 : 0)){
                s.erase({mins[y[0]], y[0]});
                mins[y[0]] = x[0] + (p[x[1]][y[1]] > 1 ? 1 : 0);
                s.insert({mins[y[0]], y[0]});
            }
        }
    }
    if(mins[n] == 1e18)
        cout << -1;
    else
        cout << mins[n];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...