Submission #625349

# Submission time Handle Problem Language Result Execution time Memory
625349 2022-08-10T05:48:47 Z EthanKim8683 Crocodile's Underground City (IOI11_crocodile) C++17
0 / 100
2 ms 4180 KB
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

using I=int;
using B=bool;
using Lli=long long int;

// dijkstra's from all exits
// only push nodes once reachable from two exits

const I N=100000;
const I M=1000000;
const I K=999999;
const Lli MAX=1e18;

vector<pair<I,I>>adjs[N];
B exis[N];
I viss[N];
Lli diss[N][2];
priority_queue<pair<Lli,I>,vector<pair<Lli,I>>,greater<pair<Lli,I>>>que;

void add(Lli dis,I a){
  viss[a]++;
  if(dis<diss[a][0]){
    diss[a][1]=diss[a][0];
    diss[a][0]=dis;
    if(viss[a]>=2)que.push({diss[a][1],a});
  }else if(dis<diss[a][1]){
    diss[a][1]=dis;
    if(viss[a]>=2)que.push({diss[a][1],a});
  }
}

I travel_plan(I n,I m,I r[][2],I l[],I k,I p[]){
  fill(&diss[0][0],&diss[0][0]+sizeof(diss)/sizeof(Lli),MAX);
  for(I i=0;i<m;i++){
    I a=r[i][0],b=r[i][1],d=l[i];
    adjs[a].push_back({b,d});
    adjs[b].push_back({a,d});
  }
  for(I i=0;i<k;i++)que.push({diss[p[i]][0]=diss[p[i]][1]=0,p[i]});
  while(!que.empty()){
    auto[dis,a]=que.top();
    que.pop();
    for(auto[b,d]:adjs[a])add(dis+d,b);
  }
  return diss[0][1];
}

#ifdef ETHANKIM8683
#include<iostream>
#include<cstdio>

I main(){
  cin.tie(0)->sync_with_stdio(0);
  I n,m;
  cin>>n>>m;
  static I r[M][2];
  for(I i=0;i<m;i++)cin>>r[i][0]>>r[i][1];
  static I l[M];
  for(I i=0;i<m;i++)cin>>l[i];
  I k;
  cin>>k;
  static I p[K];
  for(I i=0;i<k;i++)cin>>p[i];
  printf("%i\n",travel_plan(n,m,r,l,k,p));
  return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Incorrect 2 ms 4180 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Incorrect 2 ms 4180 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Incorrect 2 ms 4180 KB Output isn't correct
4 Halted 0 ms 0 KB -