제출 #853304

#제출 시각아이디문제언어결과실행 시간메모리
853304futureRobot (JOI21_ho_t4)C++17
0 / 100
3178 ms1453424 KiB
#include <bits/stdc++.h> using namespace std; int n,m; long long dp[100005]; vector<pair<int,long long>>g[100005]; map<int,long long>color[100005]; vector<array<int,4>>save; priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>>pq; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=1; i<=m; i++) { int u,v,c,p; cin>>u>>v>>c>>p; color[u][c]+=p; color[v][c]+=p; save.push_back({u,v,c,p}); } for(auto [u,v,c,p]:save) { long long minn=1e18; minn=min(minn,color[u][c]-p); for(int i=1; i<=m; i++)minn=min(minn,color[u][i]+p); g[u].push_back({v,minn}); minn=1e18; minn=min(minn,color[v][c]-p); for(int i=1; i<=m; i++)minn=min(minn,color[v][i]+p); g[v].push_back({u,minn}); } for(int i=1; i<=n; i++)dp[i]=1e18; dp[1]=0; pq.push({0,1}); while(pq.size()) { auto[_,u]=pq.top(); pq.pop(); if(dp[u]!=_)continue; for(auto v:g[u]) if(dp[v.first]>dp[u]+v.second) { dp[v.first]=dp[u]+v.second; pq.push({dp[v.first],v.first}); } } if(dp[n]==1e18)cout<<-1; else cout<<dp[n]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...