제출 #988048

#제출 시각아이디문제언어결과실행 시간메모리
988048michifiedRobot (JOI21_ho_t4)C++17
24 / 100
1497 ms113712 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; struct state_t { int id, inc; ll cost, inw; }; struct edge_t { int to, col; ll cost; }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); auto cmp = [](const state_t& a, const state_t& b){return a.cost > b.cost;}; priority_queue<state_t, vector<state_t>, decltype(cmp)> pq(cmp); ll n, m, i, tu, tv, tw, tc; cin >> n >> m; vector<vector<edge_t>> adj(n + 1); vector<unordered_map<int, ll>> coltot(n + 1); vector<unordered_map<int, vector<edge_t>>> c2e(n + 1); for (i = 0; i < m; i++) { cin >> tu >> tv >> tc >> tw; adj[tu].push_back({tv, tc, tw}); adj[tv].push_back({tu, tc, tw}); coltot[tu][tc] += tw; coltot[tv][tc] += tw; c2e[tu][tc].push_back({tv, tc, tw}); c2e[tv][tc].push_back({tu, tc, tw}); } vector<map<int, ll>> best(n + 1); pq.push({1, 0, 0}); best[1][0] = 0; while (not pq.empty()) { state_t cur = pq.top(); pq.pop(); if (cur.id == n) { cout << cur.cost; return 0; } if (cur.cost > best[cur.id][cur.inc]) continue; if (cur.inc == 0) { for (edge_t& e : adj[cur.id]) { ll tmp = cur.cost + coltot[cur.id][e.col] - e.cost; if (best[e.to].find(0) == best[e.to].end() or best[e.to][0] > tmp) { pq.push({e.to, 0, tmp, 0}); best[e.to][0] = tmp; } tmp = cur.cost + e.cost; if (best[e.to].find(e.col) == best[e.to].end() or best[e.to][e.col] > tmp) { pq.push({e.to, e.col, tmp, e.cost}); best[e.to][e.col] = tmp; } } } else { if (best[cur.id].find(0) == best[cur.id].end() or best[cur.id][0] > cur.cost) { pq.push({cur.id, 0, cur.cost, 0}); best[cur.id][0] = cur.cost; } for (edge_t& e : c2e[cur.id][cur.inc]) { ll tmp = cur.cost + coltot[cur.id][e.col] - e.cost - cur.inw; if (best[e.to].find(0) == best[e.to].end() or best[e.to][0] > tmp) { pq.push({e.to, 0, tmp, 0}); best[e.to][0] = tmp; } } } } cout << -1; return 0; }

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

Main.cpp: In function 'int main()':
Main.cpp:28:22: warning: narrowing conversion of 'tv' from 'long long int' to 'int' [-Wnarrowing]
   28 |   adj[tu].push_back({tv, tc, tw});
      |                      ^~
Main.cpp:28:26: warning: narrowing conversion of 'tc' from 'long long int' to 'int' [-Wnarrowing]
   28 |   adj[tu].push_back({tv, tc, tw});
      |                          ^~
Main.cpp:29:22: warning: narrowing conversion of 'tu' from 'long long int' to 'int' [-Wnarrowing]
   29 |   adj[tv].push_back({tu, tc, tw});
      |                      ^~
Main.cpp:29:26: warning: narrowing conversion of 'tc' from 'long long int' to 'int' [-Wnarrowing]
   29 |   adj[tv].push_back({tu, tc, tw});
      |                          ^~
Main.cpp:32:26: warning: narrowing conversion of 'tv' from 'long long int' to 'int' [-Wnarrowing]
   32 |   c2e[tu][tc].push_back({tv, tc, tw});
      |                          ^~
Main.cpp:32:30: warning: narrowing conversion of 'tc' from 'long long int' to 'int' [-Wnarrowing]
   32 |   c2e[tu][tc].push_back({tv, tc, tw});
      |                              ^~
Main.cpp:33:26: warning: narrowing conversion of 'tu' from 'long long int' to 'int' [-Wnarrowing]
   33 |   c2e[tv][tc].push_back({tu, tc, tw});
      |                          ^~
Main.cpp:33:30: warning: narrowing conversion of 'tc' from 'long long int' to 'int' [-Wnarrowing]
   33 |   c2e[tv][tc].push_back({tu, tc, tw});
      |                              ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...