제출 #870155

#제출 시각아이디문제언어결과실행 시간메모리
870155PanndaRobot (JOI21_ho_t4)C++17
34 / 100
3016 ms29428 KiB
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)4e18; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<vector<array<int, 3>>> adj(n); for (int i = 0; i < m; i++) { int u, v, color, cost; cin >> u >> v >> color >> cost; u--; v--; adj[u].push_back({ v, color, cost }); adj[v].push_back({ u, color, cost }); } map<array<int, 2>, long long> dist; // (u, par) -> distance priority_queue<array<long long, 3>, vector<array<long long, 3>>, greater<>> pq; dist[{0, -1}] = 0; pq.push({0, 0, -1}); while (!pq.empty()) { auto [d, u, p] = pq.top(); pq.pop(); if (dist.count({u, p}) && dist[{u, p}] != d) continue; map<int, long long> mp; // color to sum of cost for (auto [v, color, cost] : adj[u]) { if (v == p) continue; mp[color] += cost; } for (auto [v, color, cost] : adj[u]) { if (v == p) continue; if (!dist.count({v, u}) || dist[{v, u}] > d + cost) { dist[{v, u}] = d + cost; pq.push({ d + cost, v, u }); } if (!dist.count({v, -1}) || dist[{v, -1}] > d + mp[color] - cost) { dist[{v, -1}] = d + mp[color] - cost; pq.push({ d + mp[color] - cost, v, -1 }); } } } long long ans = INF; for (auto [arr, d] : dist) { auto [u, p] = arr; if (u == n - 1) { ans = min(ans, d); } } if (ans == INF) ans = -1; cout << ans << '\n'; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:31:25: warning: narrowing conversion of 'u' from 'std::tuple_element<1, std::array<long long int, 3> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   31 |         if (dist.count({u, p}) && dist[{u, p}] != d) continue;
      |                         ^
Main.cpp:31:28: warning: narrowing conversion of 'p' from 'std::tuple_element<2, std::array<long long int, 3> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   31 |         if (dist.count({u, p}) && dist[{u, p}] != d) continue;
      |                            ^
Main.cpp:31:41: warning: narrowing conversion of 'u' from 'std::tuple_element<1, std::array<long long int, 3> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   31 |         if (dist.count({u, p}) && dist[{u, p}] != d) continue;
      |                                         ^
Main.cpp:31:44: warning: narrowing conversion of 'p' from 'std::tuple_element<2, std::array<long long int, 3> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   31 |         if (dist.count({u, p}) && dist[{u, p}] != d) continue;
      |                                            ^
Main.cpp:39:33: warning: narrowing conversion of 'u' from 'std::tuple_element<1, std::array<long long int, 3> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   39 |             if (!dist.count({v, u}) || dist[{v, u}] > d + cost) {
      |                                 ^
Main.cpp:39:49: warning: narrowing conversion of 'u' from 'std::tuple_element<1, std::array<long long int, 3> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   39 |             if (!dist.count({v, u}) || dist[{v, u}] > d + cost) {
      |                                                 ^
Main.cpp:40:26: warning: narrowing conversion of 'u' from 'std::tuple_element<1, std::array<long long int, 3> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   40 |                 dist[{v, u}] = d + cost;
      |                          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...