답안 #74913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74913 2018-09-07T13:10:00 Z Vardanyan Cities (BOI16_cities) C++14
0 / 100
250 ms 88840 KB
//#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
const int N = 1000*100+5;
vector<pair<int,int> > g[N];
long long dp[N][(1<<5)+5];
bool c[N];
int a[6];
int IS[N];
int n,k;
long long ans = 10000000000000005;
void dfs(int v,int bitmask,long long val){
    c[v] = 1;
   // cout<<bitmask<<endl;
    if(val>=ans) return;
    if(bitmask == (1<<k)-1){
        ans = min(ans,val);
        return;
    }
    if(dp[v][bitmask]<=val && dp[v][bitmask] != -1) return;
    dp[v][bitmask] = val;
    for(int i = 0;i<g[v].size();i++){
        int to = g[v][i].first;
        int x = g[v][i].second;
        if(c[to]) x = 0;
   //     c[to] = 1;
        int btt = bitmask;

        if(IS[to] && !c[to]){
            btt|=(1<<(IS[to]-1));
        }
        dfs(to,btt,val+x);
     //   c[to] = 0;
    }
    c[v] = 0;
}
int main(){
    int m;
    scanf("%d%d%d",&n,&k,&m);
    for(int i = 1;i<=k;i++){
        scanf("%d",&a[i]);
        IS[a[i]] = i;
    }
    for(int i = 1;i<=m;i++){
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        g[x].push_back({y,z});
        g[y].push_back({x,z});
    }
    memset(dp,-1,sizeof(dp));
    for(int i = 1;i<=k;i++){
        memset(c,0,sizeof(c));
        dfs(a[i],1<<(IS[i]-1),0);
    }
    cout<<ans<<endl;
    return 0;
}

Compilation message

cities.cpp: In function 'void dfs(int, int, long long int)':
cities.cpp:22:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<g[v].size();i++){
                   ~^~~~~~~~~~~~
cities.cpp: In function 'int main()':
cities.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&k,&m);
     ~~~~~^~~~~~~~~~~~~~~~~~~
cities.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
cities.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&x,&y,&z);
         ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 71 ms 63352 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 250 ms 80260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 70 ms 80260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 241 ms 84576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 242 ms 88840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -