Submission #602394

#TimeUsernameProblemLanguageResultExecution timeMemory
602394verngutzAesthetic (NOI20_aesthetic)C++17
5 / 100
2083 ms34544 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}); } auto [d, p] = sssp(g, {1}); ll ans = d[n]; for(int i = 0; i < m; i++) { for(int j = i + 1; j < m; j++) { g.edges[i << 1].w += g.edges[j << 1].w; g.edges[(i << 1) | 1].w += g.edges[j << 1].w; auto [d2, p2] = sssp(g, {1}); ans = max(ans, d2[n]); g.edges[i << 1].w -= g.edges[j << 1].w; g.edges[(i << 1) | 1].w -= g.edges[j << 1].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...