제출 #493802

#제출 시각아이디문제언어결과실행 시간메모리
493802i_am_noobRobot (JOI21_ho_t4)C++17
100 / 100
487 ms51468 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define int ll #define rep(n) rep1(i,n) #define rep1(i,n) rep2(i,0,n) #define rep2(i,a,b) for(int i=a; i<(b); ++i) #define rep3(i,a,b) for(int i=a; i>=(b); --i) #define pii pair<int,int> #define pb push_back #define all(a) a.begin(),a.end() #define sz(a) ((int)a.size()) #define pow2(x) (1ll<<(x)) #define inf 1000'000'000'000'000'000 #ifdef i_am_noob #define bug(...) cerr << "#" << __LINE__ << ": " << #__VA_ARGS__ << "- ",_do(__VA_ARGS__) template<typename T> void _do(T x){cerr << x << endl;} template<typename T, typename ... S> void _do(T x, S ...y){cerr << x << ", ";_do(y...);} #else #define bug(...) 49 #endif const int maxn=100005; int n,m,dis[maxn]; vector<array<int,3>> adj[maxn]; vector<pii> adj2[maxn]; bool vis[maxn]; signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); cin >> n >> m; rep(m){ int u,v,a,b; cin >> u >> v >> a >> b; u--,v--; adj[u].pb({v,a,b}),adj[v].pb({u,a,b}); } rep(n){ map<int,vector<pii>> mm; map<int,int> mm2; for(auto& arr: adj[i]) mm[arr[1]].pb({arr[2],arr[0]}),mm2[arr[1]]+=arr[2]; for(auto& [c,vec]: mm){ sort(all(vec)); reverse(all(vec)); if(sz(vec)==1){ adj2[i].pb({vec[0].second,0}); continue; } for(auto p: vec) adj2[i].pb({p.second,min(p.first,mm2[c]-p.first)}); pii p1=vec[0]; for(auto p: vec) if(p!=p1) adj2[p.second].pb({p1.second,mm2[c]-p1.first}); pii p2=vec[1]; for(auto p: vec) if(p!=p2) adj2[p.second].pb({p2.second,mm2[c]-p2.first}); } } priority_queue<pii,vector<pii>,greater<pii>> pq; rep2(i,1,n) dis[i]=inf; pq.push({0,0}); while(!pq.empty()){ auto [d,u]=pq.top(); pq.pop(); if(vis[u]) continue; vis[u]=1; for(auto [v,w]: adj2[u]){ if(d+w<dis[v]){ dis[v]=d+w; pq.push({dis[v],v}); } } } cout << (dis[n-1]==inf?-1:dis[n-1]) << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...