답안 #26247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26247 2017-06-28T14:35:27 Z sgtlaugh Cities (BOI16_cities) C++14
컴파일 오류
0 ms 0 KB
#include <stdio.h>
#include <bits/stdtr1c++.h>

#define MAXK 5
#define MAXN 100010
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
#define dbg(x) cout << #x << " = " << x << endl
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))

using namespace std;

const long long INF = 1LL << 60;

bitset <MAX> visited;
int n, k, m, special[MAXK];
long long dis[1 << MAXK][MAXN];
vector <pair<int, int> > graph[MAXN];

void dijkstra(long long dis[MAXN]){
    int i, j, v, w;
    set <pair<long long, int> > S;
    for (i = 1; i <= n; i++){
        visited[i] = false;
        if (dis[i] < INF) S.insert(make_pair(dis[i], i));
    }

    while (!S.empty()){
        pair <long long, int> cur = *(S.begin());
        S.erase(cur);

        i = cur.second, visited[i] = true;
        for (j = 0; j < graph[i].size(); j++){
            v = graph[i][j].first, w = graph[i][j].second;
            if (!visited[v] && (dis[v] >  dis[i] + w)){
                dis[v] = dis[i] + w;
                S.insert(make_pair(dis[v], v));
            }
        }
    }
}

long long minimumSteinerTree(){
    int i, j, mask, submask;

    for (mask = 1; mask < (1 << k); mask++){
        for (i = 1; i <= n; i++) dis[mask][i] = INF;
        if (__builtin_popcount(mask) == 1){
            dis[mask][special[31 - __builtin_clz(mask)]] = 0;
        }
        else{
            for (i = 1; i <= n; i++){
                for (submask = mask - 1; submask >= (submask ^ mask); submask = (submask - 1) & mask){
                    dis[mask][i] = min(dis[mask][i], dis[submask][i] + dis[submask ^ mask][i]);
                }
            }
        }
        dijkstra(dis[mask]);
    }

    return *std::min_element(dis[mask - 1] + 1, dis[mask - 1] + 1 + n);
}

int main(){
    int i, j, u, v, w;

    while (scanf("%d %d %d", &n, &k, &m) != EOF){
        for (i = 0; i < MAXN; i++) graph[i].clear();
        for (i = 0; i < k; i++) scanf("%d", &special[i]);

        for (i = 0; i < m; i++){
            scanf("%d %d %d", &u, &v, &w);
            graph[u].push_back(make_pair(v, w));
            graph[v].push_back(make_pair(u, w));
        }

        printf("%lld\n", minimumSteinerTree());
    }
    return 0;
}

Compilation message

cities.cpp:15:9: error: 'MAX' was not declared in this scope
 bitset <MAX> visited;
         ^
cities.cpp:15:12: error: template argument 1 is invalid
 bitset <MAX> visited;
            ^
cities.cpp: In function 'void dijkstra(long long int*)':
cities.cpp:24:18: error: invalid types 'int[int]' for array subscript
         visited[i] = false;
                  ^
cities.cpp:32:34: error: invalid types 'int[int]' for array subscript
         i = cur.second, visited[i] = true;
                                  ^
cities.cpp:33:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < graph[i].size(); j++){
                       ^
cities.cpp:35:27: error: invalid types 'int[int]' for array subscript
             if (!visited[v] && (dis[v] >  dis[i] + w)){
                           ^
cities.cpp: In function 'long long int minimumSteinerTree()':
cities.cpp:44:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j, mask, submask;
            ^
cities.cpp: In function 'int main()':
cities.cpp:65:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j, u, v, w;
            ^
cities.cpp:69:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         for (i = 0; i < k; i++) scanf("%d", &special[i]);
                                                         ^
cities.cpp:72:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d %d", &u, &v, &w);
                                          ^