Submission #1218832

#TimeUsernameProblemLanguageResultExecution timeMemory
1218832escobrandRobot (JOI21_ho_t4)C++20
0 / 100
3094 ms66512 KiB
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(),v.end() #define eb push_back #define ll long long #define fi first #define se second int t,n,i,u,v,c,m; ll w; const int maxn = 1e5 + 10; const ll inf = 1e15; struct edge { int to,c; ll w; bool operator < (const edge &b)const { return w > b.w; } }; map<int,vector<edge>>adj[maxn]; map<int,ll> sum[maxn]; ll d[maxn]; map<int,ll> pass[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m; while(m--) { cin>>u>>v>>c>>w; adj[u][c].eb({v,c,w}); adj[v][c].eb({u,c,w}); sum[u][c] += w; sum[v][c] += w; } priority_queue<edge>q; q.push({1,0,0}); for(i = 2;i<=n;i++)d[i] = inf; while(q.size()) { i = q.top().to; w = q.top().w; c = q.top().c; q.pop(); if(c) { if(pass[i][c] != w)continue; for(auto k : adj[i][c]) { ll tmp = sum[k.to][c] - k.w; if(tmp + w < d[k.to]) { d[k.to] = tmp + w; q.push({k.to,0,d[k.to]}); } } } else { if(d[i] != w)continue; for(auto j : adj[i]) { for(auto k : j.se) { ll tmp = sum[i][k.c] - k.w; if(tmp + w < d[k.to]) { d[k.to] = tmp + w; q.push({k.to,0,d[k.to]}); } if(d[k.to] > k.w + w) { d[k.to] = k.w + w; q.push({k.to,0,d[k.to]}); } if(!pass[k.to].count(k.c) || pass[k.to][k.c] > w) { pass[k.to][k.c] = w; q.push({k.to,0,w}); } } } } } if(d[n] == inf)d[n] =-1; cout<<d[n]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...