Submission #926660

#TimeUsernameProblemLanguageResultExecution timeMemory
926660bmh123456789asdfRobot (JOI21_ho_t4)C++14
0 / 100
102 ms85936 KiB
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 1e6 + 1; const int oo = 1e16; map<int,int> cc[N]; int n, m, color[N], dp[N]; struct mmb { int vertex, dlab, prec; bool operator < (const mmb& other) const { return dlab > other.dlab; } }; struct tripple { int fi, se, th; }; vector<tripple> adj[N]; void dijikstra() { dp[1] = 0; priority_queue<mmb> Q; Q.push({1, 0}); while(!Q.empty()) { auto u = Q.top(); Q.pop(); // cout<<endl<<u.vertex<<" : "<<endl; if(u.dlab != dp[u.vertex]) continue; for(auto v : adj[u.vertex]) { // cout << v.fi<<" - "; if((cc[u.vertex][v.se] > 2 && u.prec == v.se) || (u.prec != v.se && cc[u.vertex][v.se] > 1)) { // cout<<"1 : "<<dp[v.fi]<<" "<<u.dlab + v.th<<endl; if(dp[v.fi] > u.dlab + v.th){ // cout<<"OK\n"; dp[v.fi] = u.dlab + v.th; Q.push({v.fi, dp[v.fi], v.se}); } } else { // cout<<"2 : "<<dp[v.fi]<<" "<<u.dlab + v.th<<endl; if(dp[v.fi] > u.dlab) { // cout<<"OK\n"; dp[v.fi] = u.dlab; Q.push({v.fi, dp[v.fi], v.se}); } } } } } int32_t main() { // freopen("test.inp", "r" ,stdin); // ios_base::sync_with_stdio(false); // cin.tie(0); // cout.tie(0); cin >> n >> m; for(int i = 1; i <= n; i++) dp[i] = oo; for(int i = 1; i <= m; i++) { int a, b, c, p; cin >> a >> b >> c >> p; adj[a].push_back({b, c, p}); adj[b].push_back({a, c, p}); cc[a][c]++; cc[b][c]++; } dijikstra(); if(dp[n] == oo) cout<<"-1"; else cout << dp[n]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...