Submission #740800

#TimeUsernameProblemLanguageResultExecution timeMemory
740800penguin133Swapping Cities (APIO20_swap)C++17
0 / 100
101 ms10216 KiB
#include <bits/stdc++.h> using namespace std; //#include "swap.h" //#define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); vector <pi> adj[100005]; int par[100005]; pi mn[100005]; pi mn2[100005]; int mn3[100005]; int getr(int x){return (par[x] == x ? x : par[x] =getr(par[x]));} void merge(int a, int b){a = getr(a); b = getr(b); if(a != b)par[b] = a;} void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) { vector <pii> bru; for(int i=0;i<M;i++)bru.push_back({W[i], {U[i], V[i]}}); for(int i=0;i<N;i++)mn[i] = mn2[i] = {2e9, 0}, mn3[i] = 2e9; sort(bru.begin(), bru.end()); for(auto i : bru){ int a = i.se.fi, b = i.se.se, w = i.fi; if(mn[a].fi == 2e9)mn[a] = {w, b}; else if(mn2[a].fi == 2e9)mn2[a] = {w, b}; else if(mn3[a] == 2e9)mn3[a] = w; if(mn[b].fi == 2e9)mn[b] = {w, a}; else if(mn2[b].fi == 2e9)mn2[b] = {w, a}; else if(mn3[b] == 2e9)mn3[b] = w; if(getr(a) == getr(b))continue; adj[a].push_back({b, w}); adj[b].push_back({a, w}); merge(a, b); } } vector <int> path; int tmp; int tgt; bool tr(int x, int par){ if(x == tgt){ path.push_back(x); return 1; } bool res = 0; for(auto [i, j] : adj[x]){ if(i == par)continue; bool tt = tr(i, x); res |= tt; if(tt)tmp = max(tmp, j); } if(res)path.push_back(x); return res; } int getMinimumFuelCapacity(int X, int Y) { tgt = Y; path.clear(); tmp = 0; int bruh = tr(X, -1); int ouch = 2e9; for(int i=0;i<(int)path.size();i++){ int halp = mn[path[i]].se; if(!(i && halp == path[i-1]) || (i < (int)path.size() - 1 && path[i+1] == halp))ouch = min(ouch, mn[path[i]].fi); halp = mn2[path[i]].se; if(!(i && halp == path[i-1]) || (i < (int)path.size() - 1 && path[i+1] == halp))ouch = min(ouch, mn2[path[i]].fi); ouch = min(ouch, mn3[path[i]]); } if(ouch == 2e9)return -1; return max(ouch, tmp); }

Compilation message (stderr)

swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:67:7: warning: unused variable 'bruh' [-Wunused-variable]
   67 |   int bruh = tr(X, -1);
      |       ^~~~
#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...