제출 #1208994

#제출 시각아이디문제언어결과실행 시간메모리
1208994dima2101Robot (JOI21_ho_t4)C++20
0 / 100
234 ms21080 KiB
#include <bits/stdc++.h> #define int long long struct Vert { int stop; int cost; int color; Vert() = default; Vert(int stop, int cost, int color) : stop(stop), cost(cost), color(color) {}; }; signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int n, m; std::cin >> n >> m; std::vector<std::vector<Vert>> g(n); for (int i = 0; i < m; i++) { int a, b; int c, p; std::cin >> a >> b >> c >> p; a--, b--; g[a].push_back(Vert(b, p, c)); g[b].push_back(Vert(a, p, c)); } std::vector<int> dist(n, 1e13); dist[0] = 0; std::set<std::pair<int, int>> s; s.insert({dist[0], 0}); while (s.size() > 0) { int v = s.begin()->second; s.erase(s.begin()); std::map<int, int> all; for (auto u : g[v]) { all[u.color] += u.cost; } for (auto u : g[v]) { int now = std::min(u.cost, all[u.color] - u.cost); if (dist[u.stop] > dist[v] + now) { s.erase({dist[u.stop], u.stop}); dist[u.stop] = dist[v] + now; s.insert({dist[u.stop], u.stop}); } } } if (dist[n - 1] > 1e10) { std::cout << -1; return 0; } std::cout << dist[n - 1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...