Submission #729869

# Submission time Handle Problem Language Result Execution time Memory
729869 2023-04-24T18:25:08 Z kirakaminski968 Crocodile's Underground City (IOI11_crocodile) C++17
100 / 100
585 ms 63120 KB
#include <bits/stdc++.h>
using namespace std;
int solve(int N,int M,int (*edges)[2],int *times,int K,int *positions){
    vector<pair<int,int>> adj[N];
    for(int i = 0;i<M;++i){
        adj[edges[i][0]].push_back({edges[i][1],times[i]});
        adj[edges[i][1]].push_back({edges[i][0],times[i]});
    }
    vector<int> vis(N,0); vector<vector<int>> dist(N);
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    for(int i = 0;i<K;++i){
        int cur = positions[i];
        vis[cur]++;
        dist[cur].push_back(0); dist[cur].push_back(0);
        pq.push({0,cur});
    }
    while(!pq.empty()){
        int u = pq.top().second; int dis = pq.top().first; pq.pop();
        if(vis[u] >= 2) continue;
        vis[u]++;
        if(vis[u] != 2) continue;
        if(u == 0) return dis;
        for(auto p : adj[u]){
            int v = p.first;
            if(dist[v].size() == 2){
                sort(dist[v].begin(),dist[v].end());
                if(dist[v][1] > p.second+dis){
                    dist[v].pop_back(); dist[v].push_back(dis+p.second);
                    pq.push({p.second+dis,v});
                }
            }
            else{
                dist[v].push_back(p.second+dis);
                pq.push({p.second+dis,v});
            }
        }
    }
}
int travel_plan(int N,int M,int (*R)[2],int *L,int K,int *P){
    return solve(N,M,R,L,K,P);
}

Compilation message

crocodile.cpp: In function 'int solve(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:38:1: warning: control reaches end of non-void function [-Wreturn-type]
   38 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 4 ms 700 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 4 ms 700 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 547 ms 57680 KB Output is correct
17 Correct 99 ms 18760 KB Output is correct
18 Correct 115 ms 18576 KB Output is correct
19 Correct 585 ms 63120 KB Output is correct
20 Correct 314 ms 47348 KB Output is correct
21 Correct 45 ms 7484 KB Output is correct
22 Correct 323 ms 45752 KB Output is correct