Submission #970703

#TimeUsernameProblemLanguageResultExecution timeMemory
970703htphong0909Robot (JOI21_ho_t4)C++17
34 / 100
3075 ms118004 KiB
#include <bits/stdc++.h> #define int long long using namespace std; map<int, vector<pair<int, int>>> adj[100001]; unordered_map<int, int> D[100001]; unordered_map<int, int> sum[100001]; map<int, pair<int, int>> edge[100001]; int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); //freopen("TEST.in", "r", stdin); //freopen("TEST.out", "w", stdout); int n, m; cin >> n >> m; map<int, vector<pair<int, int>>> test; for (int i = 0; i < m; i++) { int u, v, c, w; cin >> u >> v >> c >> w; adj[u][c].emplace_back(v, w); adj[v][c].emplace_back(u, w); sum[u][c] += w; sum[v][c] += w; edge[u][v] = {c, w}; edge[v][u] = {c, w}; } D[1][0] = 1; priority_queue<array<int, 3>, vector<array<int, 3>>, greater<>> q; q.push({1, 1, 0}); while (!q.empty()) { int d = q.top()[0]; int u = q.top()[1]; int t = q.top()[2]; //cerr << u << " " << t << " " << d - 1 << endl; int pc, pw; if (t == 0) tie(pc, pw) = make_pair(-1, 0); else tie(pc, pw) = edge[u][t]; q.pop(); for (const auto& [c, l] : adj[u]) { int sz = (int)l.size(); int s = sum[u][c]; if (pc == c) { sz--; s -= pw; } for (const auto& [v, w] : l) { if (v == t) continue; if (D[u][t] + w < D[v][u] || !D[v][u]) { D[v][u] = D[u][t] + w; q.push({D[v][u], v, u}); } /*if (sz == 1 && (D[u][t] < D[v][u] || !D[v][u])) { D[v][u] = D[u][t]; q.push({D[v][u], v, u}); }*/ if (D[u][t] + s - w < D[v][0] || !D[v][0]) { D[v][0] = D[u][t] + s - w; q.push({D[v][0], v, 0}); } } } } int ans = (int)1e18; for (const auto& [t, dis] : D[n]) ans = min(ans, dis); if (ans == (int)1e18) cout << -1; else cout << ans - 1; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:35:13: warning: unused variable 'd' [-Wunused-variable]
   35 |         int d = q.top()[0];
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...