Submission #494323

# Submission time Handle Problem Language Result Execution time Memory
494323 2021-12-15T06:08:56 Z keertan Crocodile's Underground City (IOI11_crocodile) C++17
100 / 100
611 ms 46828 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=2e9,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 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 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 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 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 2 ms 588 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 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 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 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 2 ms 588 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 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 568 ms 46828 KB Output is correct
17 Correct 80 ms 10484 KB Output is correct
18 Correct 84 ms 11920 KB Output is correct
19 Correct 611 ms 46800 KB Output is correct
20 Correct 443 ms 38400 KB Output is correct
21 Correct 35 ms 4536 KB Output is correct
22 Correct 362 ms 30160 KB Output is correct