Submission #1114326

#TimeUsernameProblemLanguageResultExecution timeMemory
1114326Dan4LifeRobot (JOI21_ho_t4)C++17
0 / 100
374 ms49028 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define sz(a) (int)a.size() #define all(a) begin(a),end(a) #define int long long using ar2 = array<int,2>; using ar3 = array<int,3>; const int N = (int)2e5+10; const int LINF = (int)2e18; int n, m, dis[N]; vector<ar3> adj[N]; map<int,int> node[N]; int dijkstra(){ priority_queue<ar2,vector<ar2>,greater<ar2>> pq; fill(dis,dis+n+1,LINF); dis[1]=0; pq.push({0,1}); while(sz(pq)){ auto [D,a] = pq.top(); pq.pop(); if(D!=dis[a]) continue; for(auto [b,c,p] : adj[a]){ int w = min(p,node[a][c]-p); if(dis[b]>dis[a]+w){ dis[b]=dis[a]+w; pq.push({dis[b],b}); } } } if(dis[n]==LINF) dis[n]=-1; return dis[n]; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for(int i = 1; i <= m; i++){ int a,b,c,d; cin >> a >> b >> c >> d; adj[a].pb({b,c,d}); adj[b].pb({a,c,d}); node[a][c]+=d; node[b][c]+=d; } cout << dijkstra() << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...