Submission #602818

#TimeUsernameProblemLanguageResultExecution timeMemory
602818verngutzAesthetic (NOI20_aesthetic)C++17
13 / 100
2076 ms37792 KiB
#include <bits/stdc++.h> #define err(args...) {} #ifdef DEBUG #include "_debug.cpp" #endif using namespace std; using ll = long long; using ld = long double; template <typename T> using lim = numeric_limits<T>; template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; } template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; } template <typename T> struct wedge { int u, v; T w; wedge reverse() const { return {v, u, w}; } friend ostream& operator<<(ostream& os, const wedge& e) { return os << "{u: " << e.u << ", v: " << e.v << ", w: " << e.w << "}"; } }; template <bool Directed, typename TEdge, bool Index> struct graph { using EType = TEdge; vector<TEdge> edges; vector<vector<int>> adj; graph(int n) : adj(n + Index) {} graph(int n, int m) : graph(n) { edges.reserve(m << not Directed); } TEdge& operator()(int e) { return edges[e]; } vector<int>& operator[](int u) { return adj[u]; } int size() { return adj.size() - Index; } void append(int u, const TEdge& e) { adj[u].push_back(edges.size()); edges.push_back(e); } void add_edge(const TEdge& e) { append(e.u, e); if(not Directed) append(e.v, e.reverse()); } }; template <bool Directed, typename T, bool Index> pair<vector<T>, vector<int>> sssp(graph<Directed, wedge<T>, Index>& g, const vector<int>& s) { vector<int> vis(g.adj.size()), p(g.adj.size(), -1); vector<T> d(g.adj.size(), lim<T>::max()); priority_queue<pair<T, int>> pq; for(int u : s) { pq.push({d[u] = 0, u}); } while(not pq.empty()) { int u = pq.top().second; pq.pop(); if(not vis[u]) { vis[u] = true; for(int e : g[u]) { if(not vis[g(e).v] and d[g(e).v] > d[u] + g(e).w) { pq.push({-(d[g(e).v] = d[u] + g(e).w), g(p[g(e).v] = e).v}); } } } } return {move(d), move(p)}; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; graph<0, wedge<ll>, 1> g(n, m); for(int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; g.add_edge({u, v, w}); } ll max_replace = 0; ll ans = sssp(g, {1}).first[n]; for(int i = m - 1; i >= 0; i--) { g.edges[2 * i].w += max_replace; g.edges[2 * i + 1].w += max_replace; ans = max(ans, sssp(g, {1}).first[n]); g.edges[2 * i].w -= max_replace; g.edges[2 * i + 1].w -= max_replace; max_replace = max(max_replace, g.edges[2 * i].w); } cout << 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...