Submission #969102

# Submission time Handle Problem Language Result Execution time Memory
969102 2024-04-24T13:47:21 Z vjudge1 Cities (BOI16_cities) C++17
0 / 100
66 ms 12884 KB
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;

vector<pair<int,int>> vec[100007];
vector<pair<int,pair<int,int>>> mst;
int im[10];
int dist[10][100007];
int parent[10];
map<int,int> mp;
void dijikstra(int x){
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    pq.push({0,im[x]});
    dist[x][im[x]]=0;
    int node,dis;
    while(!pq.empty()){
        node=pq.top().second;
        dis=pq.top().first;
        pq.pop();
        for(auto i:vec[node]){
            if(dis+i.first<dist[x][i.second]){
                dist[x][i.second]=dis+i.first;
                pq.push({dis+i.first,i.second});
            }
        }
    }
}

int findpar(int x){
    if(parent[x]==x) return x;
    else return parent[x]=findpar(parent[x]);
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n,k,m; cin >> n >> k >> m;
    memset(dist,0x3f,sizeof(dist));
    for(int i=0;i<k;++i){
        cin >> im[i];
        mp[im[i]]=i+1;
    }
    int a,b,c;
    for(int i=0;i<m;++i){
        cin >> a >> b >> c;
        vec[a].push_back({c,b});
        vec[b].push_back({c,a});
    }
    for(int i=0;i<k;++i) dijikstra(i);
    /*
    for(int i=0;i<k;++i){
        for(int j=1;j<=n;++j){
            cout << dist[i][j] << " ";
            if(mp[j] && i!=mp[j]-1){
                mst.push_back({dist[i][j],{i,mp[j]-1}});
                //cout << "S" << i << " " << mp[j]-1 << " " << dist[i][j] << endl;
            }
        }
        cout << endl;
    }
    sort(mst.begin(),mst.end());
    int cnt=0,run=0;
    int u,v,w;
    int ans=0;
    for(int i=0;i<k;++i) parent[i]=i;
    while(cnt<k-1 && run<mst.size()){
        u=mst[run].second.first;
        v=mst[run].second.second;
        w=mst[run].first;
        int rootu=findpar(u);
        int rootv=findpar(v);
        if(rootu!=rootv){
            parent[rootu]=rootv;
            ++cnt;
            ans+=w;
            //cout << w << endl;
        }
        ++run;
    }
    cout << ans;
    */
    int mans=1e9,cur;
    for(int j=1;j<=n;++j){
        cur=0;
        for(int i=0;i<k;++i){
            cur+=dist[i][j];
        }
        mans=min(cur,mans);
    }
    cout << mans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Incorrect 2 ms 6720 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 12884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 12884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 12828 KB Output isn't correct
2 Halted 0 ms 0 KB -