Submission #921036

# Submission time Handle Problem Language Result Execution time Memory
921036 2024-02-03T09:03:30 Z Arp Crocodile's Underground City (IOI11_crocodile) C++17
0 / 100
175 ms 262144 KB
#include<bits/stdc++.h>
#include "crocodile.h"
using namespace std;

using i64 = long long;
const i64 inf = 1e18;
const int N = 1e5;
vector<pair<int,int>> adj[N];
bool good[N],vis[N];
i64 dp[N];

void dfs(int u){
  for(auto [v,w] : adj[u]){
    if(vis[v]) continue;
    dfs(v);
  }
   vis[u] = true;
  vector<i64> a;
  for(auto [v,w] : adj[u]){
    if(!good[v]) continue;
    i64 T = dp[v] + w;
    a.push_back(T);
  }
  sort(a.begin(),a.end());
  if(a.size() >= 2){
    dp[u] = a[1];
    good[u] = true;
  }
}
void dfs2(int u){
   vis[u] = true;
  vector<i64> a;
  for(auto [v,w] : adj[u]){
    if(!good[v]) continue;
    i64 T = dp[v] + w;
    a.push_back(T);
  }
  sort(a.begin(),a.end());
  if(a.size() >= 2){
    dp[u] = a[1];
    good[u] = true;
  }
  for(auto [v,w] : adj[u]){
    if(vis[v]) continue;
    dfs2(v);
  }
  
}

int travel_plan(int N,int M,int R[][2],int L[],int K,int P[]){
  for(int i = 0;i<M;i++){
    adj[R[i][0]].emplace_back(R[i][1],L[i]);
    adj[R[i][1]].emplace_back(R[i][0],L[i]);
  }
  for(int i = 0;i<N;i++){
    vis[i] = false;
    good[i] = false;
    dp[i] = inf;
  }
  for(int i = 0;i<K;i++){
    dp[P[i]] = 0;
    good[P[i]] = true;
    vis[P[i]] = true;
  }
  dfs(0);
  for(int i = 0;i<N;i++){
    vis[i] = false;
    vis[P[i]] = true;
  }
  dfs2(0);
  assert(good[0]);
  return (int) dp[0];
}

# Verdict Execution time Memory Grader output
1 Runtime error 175 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 175 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 175 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -