답안 #1093749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093749 2024-09-27T11:09:15 Z Aviansh 악어의 지하 도시 (IOI11_crocodile) C++17
46 / 100
567 ms 262144 KB
#include <bits/stdc++.h>
#include "crocodile.h"

using namespace std;

int travel_plan(int n, int m, int edges[][2], int w[], int k, int p[])
{
    unordered_map<int,int> g[n];
    for(int i =0;i<m;i++){
        g[edges[i][0]][edges[i][1]]=w[i];
        g[edges[i][1]][edges[i][0]]=w[i];
    }
    bool ex[n];
    bool rem[n];
    bool vis[n];
    fill(rem,rem+n,0);
    fill(ex,ex+n,0);
    fill(vis,vis+n,0);
    set<array<int,3>>pq; // dist,destination,origin
    map<pair<int,int>,int>mp;
    for(int i = 0;i<k;i++){
        vis[p[i]]=1;
        ex[p[i]]=1;
    }
    for(int i = 0;i<k;i++){
        for(pair<int,int>pa : g[p[i]]){
            if(vis[pa.first]) continue;
            pq.insert({pa.second,pa.first,p[i]});
        }
    }
    while(!pq.empty()){
        array<int,3> a = *(pq.begin());
        pq.erase(pq.begin());
        if(vis[a[1]]){
            continue;
        }
        if(rem[a[1]]){
            for(pair<int,int>p:g[a[1]]){
                if(vis[p.first]) continue;
                if(mp[{a[1],p.first}]!=0&&mp[{a[1],p.first}]>a[0]+p.second){
                    pq.erase({mp[{a[1],p.first}],p.first,a[1]});
                }
                pq.insert({a[0]+p.second,p.first,a[1]});
                mp[{a[1],p.first}]=a[0]+p.second;
            }
            vis[a[1]]=1;
        }
        else{
            //cout << "removing edge: " << a[1] << " " << a[2] << "\n";
            g[a[1]].erase(a[2]);
            rem[a[1]]=1;
        }
    }
    fill(vis,vis+n,0);
    pq.clear();
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;
    q.push({0,0});
    vis[0]=1;
    while(!q.empty()){
        pair<int,int> pa = q.top();
        q.pop();
        vis[pa.second]=1;
        if(ex[pa.second]) return pa.first;
        for(pair<int,int>p:g[pa.second]){
            if(vis[p.first]) continue;
            q.push({p.second+pa.first,p.first});
        }
    }
    return -1;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 1 ms 608 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 608 KB Output is correct
8 Correct 1 ms 608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 1 ms 608 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 608 KB Output is correct
8 Correct 1 ms 608 KB Output is correct
9 Correct 4 ms 1376 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 15 ms 3072 KB Output is correct
13 Runtime error 567 ms 262144 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 1 ms 608 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 608 KB Output is correct
8 Correct 1 ms 608 KB Output is correct
9 Correct 4 ms 1376 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 15 ms 3072 KB Output is correct
13 Runtime error 567 ms 262144 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -