Submission #705489

#TimeUsernameProblemLanguageResultExecution timeMemory
705489penguin133Crocodile's Underground City (IOI11_crocodile)C++17
46 / 100
115 ms262144 KiB
#include <bits/stdc++.h> #include "crocodile.h" using namespace std; //#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()); int memo[100005]; vector <pi> adj[100000 + 5]; int dp(int x, int par){ if(memo[x] != -1)return memo[x]; int mn = 1e9, mn2 = 1e9; for(auto [i, j] : adj[x]){ if(i == par)continue; int tmp = dp(i, x) + j; if(tmp < mn)mn2 = mn, mn = tmp; else if(mn2 > tmp)mn2 = tmp; } return memo[x] = mn2; } int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { int dist[N+5][2]; for(int i=0;i<=N;i++)dist[i][0] = dist[i][1] = 2e9; for(int i=0;i<M;i++){ adj[R[i][0]].push_back({R[i][1], L[i]}); adj[R[i][1]].push_back({R[i][0], L[i]}); } /* priority_queue <pi, vector<pi>, greater<pi> > pq; for(int i=0;i<K;i++){ dist[P[i]][0] = dist[P[i]][1] = 0; pq.push({0, P[i]}); } while(!pq.empty()){ int x = pq.top().fi, y = pq.top().se; pq.pop(); if(dist[y][1] != x)continue; for(auto [i, j] : adj[y]){ if(dist[i][0] > x + j){ dist[i][1] = dist[i][0]; dist[i][0] = x + j; pq.push({dist[i][0], i}); } else if(dist[i][1] > x + j){ dist[i][1] = x + j; pq.push({dist[i][1], i}); } } } return (dist[0][1] == 1e9 ? -1 : dist[0][1]); */ memset(memo, -1, sizeof(memo)); for(int i=0;i<K;i++){ memo[P[i]] = 0; } return dp(0, -1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...