Submission #839402

#TimeUsernameProblemLanguageResultExecution timeMemory
839402Nhoksocqt1Ceste (COCI17_ceste)C++17
160 / 160
87 ms3656 KiB
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define sz(x) int((x).size()) #define fi first #define se second typedef long long ll; typedef pair<int, int> ii; template<class X, class Y> inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);} template<class X, class Y> inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int Random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } const int MAXN = 2003; struct Edge { int u, v, t, c; } edge[MAXN]; struct State { int t, c, u; State(int _t = 0, int _c = 0, int _u = 0) : t(_t), c(_c), u(_u) {}; bool operator < (const State &s) const { return (t != s.t) ? t > s.t : c > s.c; } }; ll answer[MAXN]; vector<int> adj[MAXN]; int minCost[MAXN], minCostInHeap[MAXN], numNode, numEdge; void process() { cin >> numNode >> numEdge; for (int i = 0; i < numEdge; ++i) { int u, v, t, c; cin >> u >> v >> t >> c; //u = Random(1, numNode - 1), v = Random(u + 1, numNode), t = Random(1, 100), c = Random(1, 100); cout << u << ' ' << v << ' ' << t << ' ' << c << '\n'; edge[i] = {u, v, t, c}; adj[u].push_back(i); adj[v].push_back(i); } for (int i = 1; i <= numNode; ++i) { minCost[i] = minCostInHeap[i] = 1e9; answer[i] = 1e18; } priority_queue<State> heap; heap.push({0, 0, 1}); minCostInHeap[1] = 0; while(sz(heap)) { int u(heap.top().u), dt(heap.top().t), dc(heap.top().c); heap.pop(); if(minCost[u] <= dc) continue; minCost[u] = dc; answer[u] = min(answer[u], 1LL * dt * dc); for (int it = 0; it < sz(adj[u]); ++it) { int id(adj[u][it]), v(u ^ edge[id].u ^ edge[id].v), t(edge[id].t), c(edge[id].c); if(minCost[v] > dc + c) heap.push({dt + t, dc + c, v}); } } for (int i = 2; i <= numNode; ++i) { if(answer[i] >= 1e18) answer[i] = -1; cout << answer[i] << '\n'; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); process(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...