Submission #103126

#TimeUsernameProblemLanguageResultExecution timeMemory
103126dimash241Dreaming (IOI13_dreaming)C++17
0 / 100
179 ms43764 KiB
#include "dreaming.h" #include <bits/stdc++.h> #define _USE_MATH_DEFINES_ #define ll long long #define ld long double #define Accepted 0 #define pb push_back #define mp make_pair #define sz(x) (int)(x.size()) #define every(x) x.begin(),x.end() #define F first #define S second #define For(i,x,y) for (ll i = x; i <= y; i ++) #define FOr(i,x,y) for (ll i = x; i >= y; i --) #define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) // ROAD to... Red using namespace std; const double eps = 0.000001; const ld pi = acos(-1); const int maxn = 1e7 + 9; const int mod = 1e9 + 7; const ll MOD = 1e18 + 9; const ll INF = 1e18 + 123; const int inf = 2e9 + 11; const int mxn = 1e6 + 9; const int N = 6e5 + 123; const int M = 22; const int pri = 997; const int Magic = 2101; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; int n, m, k; int u[N]; int col; int dp[N]; int ans; vector < int > comp[5], vals[N]; vector < pair < int, int > > g[N]; void dfs (int v) { u[v] = col; comp[col].pb(v); vals[v].pb(0); vals[v].pb(0); for (auto to : g[v]) { if (!u[to.F]) { dfs(to.F); vals[v].pb(dp[to.F] + to.S); sort(every(vals[v])); reverse(every(vals[v])); vals[v].pop_back(); dp[v] = max(dp[v], dp[to.F] + to.S); } } ans = max(ans, vals[v][0] + vals[v][1]); } void calc (int v, int par = 0, int upp = 0) { ans = max(ans, dp[v] + upp); dp[v] = max(dp[v], upp); for (auto to : g[v]) { if (to.F == par) continue; int nxt = upp; if (dp[to.F] + to.S == vals[v][0]) nxt = max(nxt, vals[v][1]); else nxt = max(nxt, vals[v][0]); calc (to.F, v, nxt + to.S); } } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { n = N, m = M, k = L; for (int i = 1; i <= m; i ++) { int l, r, x; l = A[i - 1], r = B[i - 1], x = T[i - 1]; g[l].pb(mp(r, x)); g[r].pb(mp(l, x)); } if (n - 2 == m) { for (int i = 0; i < n; i ++) if (!u[i]) { col ++; dfs(i); } calc(comp[1][0]); calc(comp[2][0]); int mn1 = comp[1][0]; int mn2 = comp[2][0]; for (auto e : comp[1]) if (dp[mn1] > dp[e]) mn1 = e; for (auto e : comp[2]) if (dp[mn2] > dp[e]) mn2 = e; g[mn1].pb(mp(mn2, k)); g[mn2].pb(mp(mn1, k)); for (int i = 0; i < n; i ++) u[i] = 0; dfs(0); calc(0); return (int)ans; } return 18; }
#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...