제출 #925309

#제출 시각아이디문제언어결과실행 시간메모리
925309crafticatRobot (JOI21_ho_t4)C++17
0 / 100
3012 ms36752 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<ll,ll>; constexpr ll inf = 1e12 + 7; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; // Custom hash function for pairs of long long struct pair_hash { template <class T1, class T2> std::size_t operator () (const std::pair<T1, T2> &pair) const { auto hash1 = std::hash<T1>{}(pair.first); auto hash2 = std::hash<T2>{}(pair.second); return hash1 ^ hash2; } }; // Define hash table with custom hash function template <class K, class V> using ht = gp_hash_table< K, V, pair_hash, equal_to<K>, direct_mask_range_hashing<>, linear_probe_fn<>, hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<>, true>>; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ll n, m; cin >> n >> m; vector<vector<tuple<ll,ll,ll>>> f(n + 1); for (ll i = 0; i < m; ++i) { ll a, b, c, d; cin >> a >> b >> c >> d; f[a].emplace_back(c,b,d); f[b].emplace_back(c,a,d); } vector<map<ll, ll>> apps(n + 1); vector<vector<tuple<ll,ll,ll>>> g(n + 1); for (ll i = 1; i <= n; ++i) { for (auto [c, node, d] : f[i]) { g[i].emplace_back(node,d,c); } } for (int i = 1; i <= n; ++i) { map<ll, ll> app; for (auto [child,len, c] : g[i]) { app[c] += len; } apps[i] = app; } priority_queue<tuple<ll,ll,ll,ll>,vector<tuple<ll,ll,ll,ll>>,greater<>> pq; pq.emplace(0,1,0,0); vector<ll> d(n + 1,inf); ht<pair<long long, long long>, int> visited; while (!pq.empty()) { auto [cost, cur, col, lastCost] = pq.top();pq.pop(); if (visited[{cur,col}]) continue; d[cur] = min(d[cur],cost); visited[{cur,col}] = true; for (auto [child, len, c] : g[cur]) { if (visited[{child,cur}]) continue; pq.emplace(cost + len,child,c,1e9 - len); int appSum = apps[cur][c] - (c == col ? (1e9 - lastCost) : 0); pq.emplace(cost + appSum - len,child,-1,-1); } } if (d[n] == inf) { cout << "-1"; return 0; } cout << d[n]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...