Submission #1140911

#TimeUsernameProblemLanguageResultExecution timeMemory
1140911buzdiRobot (JOI21_ho_t4)C++17
0 / 100
347 ms41436 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int NMAX = 1e5; const ll INF = 1e18; struct PQElement { int node, parent, parent_c; ll d; bool operator < (const PQElement &other) const { return other.d < d; } }; struct Edge { int next_node, c, p; Edge(int next_node, int c, int p) : next_node(next_node), c(c), p(p) {} }; int n, m; ll d[NMAX + 1]; vector<Edge> g[NMAX + 1]; unordered_map<int, int> mp[NMAX + 1]; void Dijkstra(int start) { for(int i = 1; i <= n; i++) { d[i] = INF; } priority_queue<PQElement> pq; pq.push({start, 0}); while(!pq.empty()) { auto [node, parent, parent_c, curent_d] = pq.top(); pq.pop(); if(d[node] == INF) { d[node] = curent_d; for(auto [next_node, c, p] : g[node]) { if(mp[node][c] - (parent_c == c) == 1) { pq.push({next_node, node, 0, curent_d}); } else { pq.push({next_node, node, c, curent_d + p}); } } } } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 1; i <= m; i++) { int a, b, c, p; cin >> a >> b >> c >> p; g[a].emplace_back(b, c, p); mp[a][c]++; g[b].emplace_back(a, c, p); mp[b][c]++; } Dijkstra(1); cout << (d[n] == INF ? -1 : d[n]); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...