Submission #706239

#TimeUsernameProblemLanguageResultExecution timeMemory
706239becaidoRobot (JOI21_ho_t4)C++17
0 / 100
281 ms48208 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second const ll INF = 1e18; const int SIZE = 2e5 + 5; int n, m; ll dis[SIZE]; int wei[SIZE]; unordered_set<int> us[SIZE]; unordered_map<int, vector<tuple<int, int, int>>> adj[SIZE]; priority_queue<tuple<ll, int, int, int>, vector<tuple<ll, int, int, int>>, greater<tuple<ll, int, int, int>>> pq; void solve() { cin >> n >> m; for (int i = 1; i <= m; i++) { int a, b, c, w; cin >> a >> b >> c >> w; adj[a][c].pb(b, w, i); adj[b][c].pb(a, w, i); wei[i] = w; } fill(dis + 1, dis + n + 1, INF); pq.emplace(0, 1, 0, 0); while (pq.size()) { auto [d, pos, color, eid] = pq.top(); pq.pop(); if (us[pos].count(color)) continue; dis[pos] = min(dis[pos], d); if (us[pos].count(0) == 0) { for (auto [c, v] : adj[pos]) { ll sum = 0; for (auto [np, w, id] : v) if (id != eid) sum += w; for (auto [np, w, id] : v) if (id != eid) { pq.emplace(d + w, np, c, id); pq.emplace(d + sum - w, np, 0, 0); } } } ll sum = 0; for (auto [np, w, id] : adj[pos][color]) if (id != eid) sum += w; for (auto [np, w, id] : adj[pos][color]) if (id != eid) { pq.emplace(d + w, np, color, id); pq.emplace(d + sum - w - wei[eid], np, 0, 0); } us[pos].insert(0); us[pos].insert(color); } cout << (dis[n] == INF ? -1 : dis[n]) << '\n'; } int main() { Waimai; solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...