Submission #996441

#TimeUsernameProblemLanguageResultExecution timeMemory
996441vjudge1Robot (JOI21_ho_t4)C++17
0 / 100
79 ms31152 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (b); i >= (a); i --) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPD(i, n) for (int i = (n) - 1; i >= 0; --i) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) constexpr ll LINF = (1ll << 60); constexpr int INF = (1ll << 30); constexpr int Mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* Phu Trong from Nguyen Tat Thanh High School for gifted student */ template <class X, class Y> bool minimize(X &x, const Y &y){ X eps = 1e-9; if (x > y + eps) {x = y; return 1;} return 0; } template <class X, class Y> bool maximize(X &x, const Y &y){ X eps = 1e-9; if (x + eps < y) {x = y; return 1;} return 0; } int numNode, numEdge; #define MAX_NODE 200005 #define MAX_EDGE 300005 struct Edge{ int u, v, color, cost; Edge(){} Edge(int _u, int _v, int _color, int _cost){ u = _u, v = _v, color = _color, cost = _cost; } int other(int x){return (x ^ u ^ v);} } edge[MAX_EDGE]; struct custom_hash{ size_t operator ()(uint64_t x) const { static const uint64_t FIXED_RANDOM = (chrono::steady_clock::now().time_since_epoch().count()); x ^= FIXED_RANDOM; return (x ^ (x >> 16)); } }; vector<int> G[MAX_NODE]; unordered_map<int, int, custom_hash> cnt[MAX_NODE]; void loadGraph(void){ cin >> numNode >> numEdge; for (int i = 1; i <= numEdge; ++i){ cin >> edge[i].u >> edge[i].v >> edge[i].color >> edge[i].cost; G[edge[i].u].emplace_back(i); G[edge[i].v].emplace_back(i); int v = edge[i].color; cnt[edge[i].u][v]++; cnt[edge[i].v][v]++; } } int F[MAX_NODE]; void process(void){ memset(F, 0x3f, (numNode + 1) * sizeof(int)); #define T tuple<int, int, int> priority_queue<T, vector<T>, greater<T>> q; q.emplace(0, 1, 0); F[1] = 0; while(q.size()){ int du, u, l_color; tie(du, u, l_color) = q.top(); q.pop(); if (du > F[u]) continue; for (int &i : G[u]){ int v = edge[i].other(u); int cost = ((cnt[u][edge[i].color] - (l_color == edge[i].color)) <= 1 ? 0 : edge[i].cost); if (minimize(F[v], F[u] + cost)){ q.emplace(F[v], v, edge[i].color); } } } cout << (F[numNode] >= INF ? -1 : F[numNode]); } signed main(){ #define name "Whisper" cin.tie(nullptr) -> sync_with_stdio(false); //freopen(name".inp", "r", stdin); //freopen(name".out", "w", stdout); loadGraph(); process(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...