Submission #983966

#TimeUsernameProblemLanguageResultExecution timeMemory
983966vjudge1Robot (JOI21_ho_t4)C++17
0 / 100
546 ms59296 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define print(a) for(auto x : a) cout << x << ' '; cout << endl; #define str string signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<array<int, 3>> graph[n + 1]; map<int, int> p[n + 1]; for(int i = 0; i < m; i ++){ int a, b, c, P; cin >> a >> b >> c >> P; graph[a].push_back({b, c, P}); graph[b].push_back({a, c, P}); p[a][c] += P; p[b][c] += P; } vector<vector<int>> mins(n + 1, vector<int> (2, 1e18)), color(n + 1, vector<int> (2)), price(n + 1, vector<int> (2)); set<array<int, 5>> s; s.insert({0, 1, 0, 0, 0}); s.insert({0, 1, 1, 0, 0}); mins[1][0] = 0; mins[1][1] = 0; while(!s.empty()){ array<int, 5> x = *s.begin(); s.erase(s.begin()); if(x[2] == 0){ for(auto y : graph[x[1]]){ if(mins[y[0]][0] > x[0] + y[2]){ s.erase({mins[y[0]][0], y[0], 0, color[y[0]][0], price[y[0]][0]}); mins[y[0]][0] = x[0] + y[2]; color[y[0]][0] = y[1]; price[y[0]][0] = y[2]; s.insert({mins[y[0]][0], y[0], 0, color[y[0]][0], price[y[0]][0]}); } if(mins[y[0]][1] > x[0] + p[x[1]][y[1]] - y[2] - (x[3] == y[2] ? x[4] : 0)){ s.erase({mins[y[0]][1], y[0], 1, color[y[0]][1], price[y[0]][1]}); mins[y[0]][1] = x[0] + p[x[1]][y[1]] - y[2] - (x[3] == y[2] ? x[4] : 0); color[y[0]][1] = y[1]; price[y[0]][1] = y[2]; s.insert({mins[y[0]][1], y[0], 1, color[y[0]][1], price[y[0]][ 1]}); } } } else{ for(auto y : graph[x[1]]){ if(mins[y[0]][0] > x[0] + y[2]){ s.erase({mins[y[0]][0], y[0], 0, color[y[0]][0], price[y[0]][0]}); mins[y[0]][0] = x[0] + y[2]; color[y[0]][0] = y[1]; price[y[0]][0] = y[2]; s.insert({mins[y[0]][0], y[0], 0, color[y[0]][0], price[y[0]][0]}); } if(mins[y[0]][1] > x[0] + p[x[1]][y[1]] - y[2]){ s.erase({mins[y[0]][1], y[0], 1, color[y[0]][1], price[y[0]][1]}); mins[y[0]][1] = x[0] + p[x[1]][y[1]] - y[2]; color[y[0]][1] = y[1]; price[y[0]][1] = y[2]; s.insert({mins[y[0]][1], y[0], 1, color[y[0]][1], price[y[0]][1]}); } } } } if(min(mins[n][0], mins[n][1]) == 1e18) cout << -1; else cout << min(mins[n][0], mins[n][1]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...