답안 #1027891

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027891 2024-07-19T10:58:29 Z hasan2006 Cities (BOI16_cities) C++17
0 / 100
1164 ms 51864 KB
#include <bits/stdc++.h>

using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 1e5 + 9 , mod = 1e9 + 7;
ll  dp[N][40] ,  c[N] , d[N] , a[N] , b[N] ,  p[N];
vector<pair<int,int>>v[N];


void solve()
{
    ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
    cin>>n>>k>>m;

    for(i = 0; i < (1 << k); i++)
        for(j = 0; j < n; j++)
            dp[j][i] = 1e18;
    for(i = 1; i <= k; i++)
        cin>>x , dp[x - 1][(1 << (i - 1))] = 0;
    for(i = 1; i <= m; i++){
        cin>>l>>r>>x;
        l-- , r--;
        v[l].pb({r , x});
        v[r].pb({l , x});
    }
    for(i = 1; i  < (1 << k); i++){
        for(j = 1; j < i; j++){
            x = i ^ j;
            if((j | i) != i || x > j)
                continue;
            for(f = 0; f < n; f++)
                dp[f][i] = min(dp[f][i] , dp[f][j] + dp[f][x]);
        }
        priority_queue<pair<int,int>>q;
        for(j = 0; j < n; j++){
            c[j] = 0;
            if(dp[j][i] < 1e18)
                q.push({-dp[j][i] , j});
        }
        while(!q.empty()){
            x = q.top().second , y = -q.top().first;
            q.pop();
            if(c[x])
                continue;
            c[x] = 1;
            for(auto to : v[x]){
                if(to.se + y < dp[to.fi][i]){
                    dp[to.fi][i] = to.se + y;
                    q.push({-dp[to.fi][i] , to.fi});
                }
            }
        }
    }
    for(i = 0; i < n; i++)
        mn = min(mn , dp[i][(1 << k)  - 1]);
    cout<<mn<<"\n";
}


int main(){
    TL;
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
    int t = 1;
//    cin>>t;
    while(t--)
     {
        solve();
     }
}
// Author : حسن

Compilation message

cities.cpp: In function 'void solve()':
cities.cpp:28:12: warning: unused variable 'q' [-Wunused-variable]
   28 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |            ^
cities.cpp:28:38: warning: unused variable 's' [-Wunused-variable]
   28 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                      ^
cities.cpp:28:69: warning: unused variable 'mx' [-Wunused-variable]
   28 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                                     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Incorrect 1 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 287 ms 51540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 602 ms 51864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1164 ms 51628 KB Output isn't correct
2 Halted 0 ms 0 KB -