Submission #1087961

#TimeUsernameProblemLanguageResultExecution timeMemory
1087961T0p_Crocodile's Underground City (IOI11_crocodile)C++14
46 / 100
2 ms3164 KiB
#include "crocodile.h"
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAX_N = 100000 + 5;
 
int degree[MAX_N];
long long mn_1[MAX_N], mn_2[MAX_N];
bool is_process[MAX_N];
vector<pair<int, long long>> g[MAX_N];
 
void update(int u, long long v) {
  if (v < mn_1[u]) {
    mn_2[u] = mn_1[u];
    mn_1[u] = v;
  }
  else {
    mn_2[u] = min(mn_2[u], v);
  }
}
 
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
  for (int i=0 ; i<N ; i++) {
    mn_1[i] = mn_2[i] = 2e9;
  }
 
  for (int i=0 ; i<M ; i++) {
    g[R[i][0]].push_back({ R[i][1], L[i] });
    g[R[i][1]].push_back({ R[i][0], L[i] });
 
    degree[R[i][0]]++;
    degree[R[i][1]]++;
  }
 
  queue<int> topo;
 
  for (int i=0 ; i<K ; i++) {
    is_process[P[i]] = true;
    topo.push(P[i]);
    mn_1[P[i]] = mn_2[P[i]] = 0;
  }
  
  while (!topo.empty()) {
    int u = topo.front();
    topo.pop();
 
    for (pair<int, long long> edge : g[u]) {
      degree[edge.first]--;
      update(edge.first, mn_2[u] + edge.second);
 
      if (edge.first != 0 && !is_process[edge.first] && degree[edge.first] == 1) {
        is_process[edge.first] = true;
        topo.push(edge.first);
      }
    }
  }
 
  return mn_2[0];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...