답안 #975902

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975902 2024-05-06T02:48:27 Z Nipphitch Cities (BOI16_cities) C++14
100 / 100
1676 ms 49516 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3,unroll-loops")
#pragma GCC target ("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define ll long long
#define pii pair <ll,int>
const int N=1e5+5;
const int K=40;
const ll INF=LLONG_MAX/2;

int n,k,m;
ll dp[K][N];
vector <pii> adj[N];
priority_queue <pii,vector<pii>,greater<pii>> pq;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    fill_n(dp[0],K*N,INF);
    cin >> n >> k >> m;
    for(int i=0;i<k;i++){
        int x;
        cin >> x;
        dp[(1<<i)][x]=0;
    }
    for(int i=0;i<m;i++){
        int u,v,w;
        cin >> u >> v >> w;
        adj[u].push_back({v,w});
        adj[v].push_back({u,w});
    }
    for(int mask1=1;mask1<(1<<k);mask1++){
        for(int mask2=1;mask2<mask1;mask2++) if(mask1&mask2) for(int i=1;i<=n;i++) dp[mask1][i]=min(dp[mask1][i],dp[mask2][i]+dp[mask1^mask2][i]);
        for(int i=1;i<=n;i++) if(dp[mask1][i]!=INF) pq.push({dp[mask1][i],i});
        while(!pq.empty()){
            auto [d_u,u]=pq.top();
            pq.pop();
            for(auto [v,w]:adj[u]) if(dp[mask1][v]>d_u+w) pq.push({dp[mask1][v]=d_u+w,v});
        }
    }
    cout << *min_element(dp[(1<<k)-1]+1,dp[(1<<k)-1]+1+n);
}

Compilation message

cities.cpp: In function 'int main()':
cities.cpp:37:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |             auto [d_u,u]=pq.top();
      |                  ^
cities.cpp:39:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   39 |             for(auto [v,w]:adj[u]) if(dp[mask1][v]>d_u+w) pq.push({dp[mask1][v]=d_u+w,v});
      |                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 33884 KB Output is correct
2 Correct 5 ms 33884 KB Output is correct
3 Correct 5 ms 33884 KB Output is correct
4 Correct 6 ms 33884 KB Output is correct
5 Correct 5 ms 33884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 457 ms 49092 KB Output is correct
2 Correct 416 ms 48196 KB Output is correct
3 Correct 221 ms 41416 KB Output is correct
4 Correct 54 ms 42916 KB Output is correct
5 Correct 208 ms 49104 KB Output is correct
6 Correct 52 ms 43092 KB Output is correct
7 Correct 7 ms 34140 KB Output is correct
8 Correct 7 ms 34140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 34140 KB Output is correct
2 Correct 10 ms 34140 KB Output is correct
3 Correct 7 ms 34140 KB Output is correct
4 Correct 7 ms 34140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 820 ms 48820 KB Output is correct
2 Correct 802 ms 49464 KB Output is correct
3 Correct 500 ms 41416 KB Output is correct
4 Correct 484 ms 46660 KB Output is correct
5 Correct 137 ms 43444 KB Output is correct
6 Correct 62 ms 45296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1676 ms 49096 KB Output is correct
2 Correct 1676 ms 49516 KB Output is correct
3 Correct 1555 ms 48028 KB Output is correct
4 Correct 996 ms 41416 KB Output is correct
5 Correct 911 ms 46784 KB Output is correct
6 Correct 212 ms 44016 KB Output is correct
7 Correct 78 ms 45644 KB Output is correct