Submission #406412

#TimeUsernameProblemLanguageResultExecution timeMemory
406412Jarif_RahmanRobot (JOI21_ho_t4)C++17
0 / 100
262 ms21940 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll inf = 1e18; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<vector<tuple<int, int, ll>>> v(n); for(int i = 0; i < m; i++){ int a, b, c; ll p; cin >> a >> b >> c >> p; a--, b--, c--;; v[a].pb({b, c, p}); v[b].pb({a, c, p}); } vector<ll> dis(n, inf); vector<bool> bl(n, 0); priority_queue<tuple<ll, int, int, ll, int>> pq; dis[0] = 0; pq.push({0, 0, -1, -1, -1}); while(!pq.empty()){ auto [ig, nd, cl, pr, nd0] = pq.top(); pq.pop(); if(bl[nd]) continue; bl[nd] = 1; map<int, ll> mp; for(auto [x, c, p]: v[nd]) mp[c]+=p; for(auto [x, c, p]: v[nd]){ ll w = min(p, mp[c]-p-(cl==c && x!=nd0)*(pr)); if(dis[nd]+w < dis[x]){ dis[x] = dis[nd]+w; pq.push({-dis[x], x, c, w, nd}); } } } cout << (dis[n-1]==inf?-1:dis[n-1]) << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...