제출 #1092314

#제출 시각아이디문제언어결과실행 시간메모리
1092314PagodePaivaRobot (JOI21_ho_t4)C++17
0 / 100
3 ms660 KiB
#include<bits/stdc++.h>
#define int long long
#define inf 1e18;

using namespace std;

const int N = 1010;
vector <array <int, 3>> gg[N];
vector <pair <int,int>> g[N];
int dist[N];

int32_t main(){
    int n, m;
    cin >> n >> m;
    for(int i = 0;i < m;i++){
        int a, b, c, p;
        cin >> a >> b >> c >> p;
        gg[a].push_back({b, c, p});
        gg[b].push_back({a, c, p});
    }
    for(int v = 1;v <= n;v++){
        for(auto x : gg[v]){
            auto [y, c, p] = x;
            int sum = 0;
            for(auto [_, cc, d] : gg[v]){
                if(cc == c and _ != y) sum += d;
            }
            if(sum == 0) g[v].push_back({y, 0});
            else g[v].push_back({y, min(sum, p)});
        }
    }
    priority_queue <pair <int, int>> pq;
    pq.push({0, 1});
    for(int i = 1;i <= n;i++) dist[i] = inf;
    dist[1] = 0;
    while(!pq.empty()){
        auto [d, v] = pq.top();
        pq.pop();
        d *= -1;
        if(d != dist[v]) continue;
        for(auto [x, w] : g[v]){
            if(dist[x] > dist[v] + w){
                dist[x] = dist[v] + w;
                pq.push({-dist[x], x});
            }
        }
    }
    int aa = inf;
    if(dist[n] == aa){
        cout << -1 << '\n';
        return 0;
    }
    cout << dist[n] << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...