Submission #125420

#TimeUsernameProblemLanguageResultExecution timeMemory
125420abacabaCeste (COCI17_ceste)C++14
16 / 160
2562 ms131076 KiB
#include <bits/stdc++.h> using namespace std; #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define mp make_pair #define f first #define se second #define pb push_back #define ppb pop_back #define ll long long #define ull unsigned long long #define cntbit(x) __builtin_popcount(x) #define uset unordered_set #define umap unordered_map #define pii pair<int, int> #define ld long double #define pll pair<long long, long long> struct edge { int to, t, cost; edge(int to, int t, int cost) : to(to), t(t), cost(cost) {} bool operator < (const edge &b) const { if(to == b.to) { if(t == b.t) return cost < b.cost; return t < b.t; } return to < b.to; } }; struct point { int u, v, t, cost; point(int u, int v, int t, int cost) : u(u), v(v), t(t), cost(cost) {} }; const ll inf = 2e15; const int N = 2e3 + 15; int n, m; map <int, int> d[N]; set <edge> g[N]; vector <point> edges; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 1; i <= m; ++i) { int u, v, t, c; cin >> u >> v >> t >> c; edges.pb(*new point(u, v, t, c)); edges.pb(*new point(v, u, t, c)); } d[1][0] = 0; m <<= 1; for(int i = 1; i <= n; ++i) { for(int j = 0; j < m; ++j) { int u = edges[j].u, v = edges[j].v, t = edges[j].t, cost = edges[j].cost; for(map <int, int>::iterator it = d[u].begin(); it != d[u].end(); ++it) { if(d[v].find(it->f + t) == d[v].end() || d[u][it->f] + cost < d[v][it->f + t]) d[v][it->f + t] = d[u][it->f] + cost; } } } for(int i = 2; i <= n; ++i) { ll ans = inf; for(map <int, int>::iterator it = d[i].begin(); it != d[i].end(); ++it) ans = min(ans, it->f * (ll)it->se); cout << (ans == inf ? - 1 : ans) << endl; } 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...