Submission #814344

#TimeUsernameProblemLanguageResultExecution timeMemory
814344MohamedAhmed04Robot (JOI21_ho_t4)C++14
100 / 100
637 ms46952 KiB
#include <bits/stdc++.h> using namespace std ; const long long inf = 1e18 ; const int MAX = 1e5 + 10 ; int arr[MAX] ; int n , m ; vector< vector< array<int , 3> > >adj(MAX) ; long long dist[MAX] ; map< pair<int , int> , long long>mp , mp2 ; void dijkstra(int src) { for(int i = 1 ; i <= n ; ++i) dist[i] = inf ; priority_queue< pair<long long , int> , vector< pair<long long , int> > , greater< pair<long long , int> > >q ; dist[src] = 0 ; q.push({0 , src}) ; while(!q.empty()) { pair<long long , int>p = q.top() ; q.pop() ; int node = p.second ; long long cost = p.first ; if(dist[node] < cost) continue ; for(auto &childd : adj[node]) { mp2[{node , childd[0]}] = max(mp2[{node , childd[0]}] , 1ll * childd[2] - (dist[childd[1]] + childd[2] - dist[node])) ; } for(auto &childd : adj[node]) { int child2 = childd[1] ; long long cost2 = cost + min(1ll * childd[2] , mp[{node , childd[0]}] - childd[2] - mp2[{node , childd[0]}]) ; if(cost2 < dist[child2]) { dist[child2] = cost2 ; q.push({cost2 , child2}) ; } } } } int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n>>m ; for(int i = 0 ; i < m ; ++i) { int x , y , c , w ; cin>>x>>y>>c>>w ; adj[x].push_back({c , y , w}) ; adj[y].push_back({c , x , w}) ; mp[{x , c}] += w , mp[{y , c}] += w ; } dijkstra(1) ; if(dist[n] == inf) dist[n] = -1 ; return cout<<dist[n]<<"\n" , 0 ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...