Submission #494324

# Submission time Handle Problem Language Result Execution time Memory
494324 2021-12-15T06:10:28 Z keertan Crocodile's Underground City (IOI11_crocodile) C++17
100 / 100
635 ms 46980 KB
#include "crocodile.h"
#include<bits/stdc++.h>
using namespace std;

#define all(x) x.begin(),x.end()
#define all1(x) x.rbegin(),x.rend()
#define sz(x) (int)(x.size())
const int N=1e4+5,N1=2147483647,mod=1e9+7;

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
  int n,m,k;
  n=N;
  m=M;
  k=K;
 
  using gh=pair<int,int>;
  vector<pair<int,int>> adj[n];
  for (int i=0,u,v,w;i<m;i++){
    u=R[i][0],v=R[i][1],w=L[i];
    adj[u].emplace_back(v,w);
    adj[v].emplace_back(u,w);
  }
  vector<gh> dis(n,{N1,N1});
  priority_queue<gh,vector<gh>,greater<gh>> q;
  vector<bool> vis(n);
  for (int i=0,x;i<k;i++){
    x=P[i];
    q.emplace(0,x);
    dis[x]={0,0};
  }
  while(!q.empty()){
    int u,dis1;
    tie(dis1,u)=q.top();
    q.pop();
    //cerr<<u<<" "<<dis1<<"\n";
    if (vis[u]){continue;}
    vis[u]=1;
    for (const gh &it:adj[u]){
      int cur=dis1+it.second;
      if (dis[it.first].first>=cur){
        dis[it.first].second=dis[it.first].first;
        dis[it.first].first=cur;
      }
      else if (cur<dis[it.first].second){
        dis[it.first].second=cur;
      }
      if (dis[it.first].first!=N1 && dis[it.first].second!=N1 && !vis[it.first]){
        q.emplace(dis[it.first].second,it.first);
      }
    }
  }
  
  return dis[0].second;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 5 ms 716 KB Output is correct
13 Correct 3 ms 844 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 5 ms 716 KB Output is correct
13 Correct 3 ms 844 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 570 ms 46980 KB Output is correct
17 Correct 68 ms 10436 KB Output is correct
18 Correct 86 ms 11848 KB Output is correct
19 Correct 635 ms 46796 KB Output is correct
20 Correct 406 ms 38396 KB Output is correct
21 Correct 35 ms 4568 KB Output is correct
22 Correct 373 ms 30320 KB Output is correct