제출 #482100

#제출 시각아이디문제언어결과실행 시간메모리
482100ShinRobot (JOI21_ho_t4)C++14
0 / 100
111 ms22088 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define all(x) x.begin(), x.end() using namespace std; const int N = 2e5 + 7; const int MOD = 1e9 + 7; // 998244353; const int INF = 1e9 + 7; const long long INFLL = 1e18 + 7; template <class X, class Y> bool minimize(X &a, Y b) { if (a > b) return a = b, true; return false; } template <class X, class Y> bool maximize(X &a, Y b) { if (a < b) return a = b, true; return false; } struct edge { int to, color; long long cost; edge() {} edge(int _to, int _color, long long _cost) { to = _to; color = _color; cost = _cost; } }; int n, m; long long dist[N]; long long sum[N]; vector<edge> adj[N]; void solve(void) { cin >> n >> m; for (int i = 1; i <= m; i ++) { int u, v, c, w; cin >> u >> v >> c >> w; adj[u].emplace_back(v, c, w); adj[v].emplace_back(u, c, w); } memset(dist, 0x3f, sizeof dist); priority_queue<pair<long long, int>> heap; dist[1] = 0; heap.emplace(0, 1); while (!heap.empty()) { int u; long long d_u; tie(d_u, u) = heap.top(); heap.pop(); d_u = -d_u; for (edge x: adj[u]) { sum[x.color] += x.cost; } for (edge x: adj[u]) { if (minimize(dist[x.to], d_u + min(1LL * x.cost, sum[x.color] - x.cost))) { heap.emplace(-dist[x.to], x.to); } } for (edge x: adj[u]) { sum[x.color] = 0; } } cout << (dist[n] < INFLL ? dist[n] : -1); } int main(void) { cin.tie(0)->sync_with_stdio(0); int test = 1; // cin >> test; while (test --) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...