답안 #96941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96941 2019-02-12T19:51:50 Z Kastanda Cities (BOI16_cities) C++11
37 / 100
3283 ms 69600 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 100005, K = 5;
int n, m, k, A[K], Pq[N * 10];
bool M[N];
long long dp[1 << K][N];
vector < pair < int , int > > Adj[N];
int main()
{
    scanf("%d%d%d", &n, &k, &m);
    memset(dp, 63, sizeof(dp));
    for (int i = 0; i < k; i++)
        scanf("%d", &A[i]), dp[1 << i][A[i]] = 0;
    for (int i = 1; i <= m; i++)
    {
        int v, u, w;
        scanf("%d%d%d", &v, &u, &w);
        Adj[v].push_back({u, w});
        Adj[u].push_back({v, w});
    }
    for (int mask = 1; mask < (1 << k); mask ++)
    {
        if (__builtin_popcount(mask) > 1)
            for (int v = 1; v <= n; v ++)
                for (int sub = mask; sub; sub = (sub - 1) & mask)
                    if (sub && (sub ^ mask))
                        for (auto &u : Adj[v])
                            if (dp[mask][v] > dp[sub][v] + dp[mask ^ sub][u.first] + u.second)
                                dp[mask][v] = dp[sub][v] + dp[mask ^ sub][u.first] + u.second;
        int l = 0, r = 0;
        for (int v = 1; v <= n; v ++)
            Pq[r ++] = v, M[v] = 1;
        while (r - l)
        {
            int v = Pq[l ++]; M[v] = 0;
            for (auto &u : Adj[v])
                if (dp[mask][u.first] > dp[mask][v] + u.second)
                {
                    dp[mask][u.first] = dp[mask][v] + u.second;
                    if (!M[u.first])
                        M[u.first] = 1, Pq[r ++] = u.first;
                }
        }
    }
    return !printf("%lld\n", dp[(1 << k) - 1][A[0]]);
}

Compilation message

cities.cpp: In function 'int main()':
cities.cpp:10: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:13:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]), dp[1 << i][A[i]] = 0;
         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
cities.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &v, &u, &w);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 27776 KB Output is correct
2 Correct 23 ms 27776 KB Output is correct
3 Correct 22 ms 27776 KB Output is correct
4 Correct 24 ms 27768 KB Output is correct
5 Correct 25 ms 27720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 534 ms 35576 KB Output is correct
2 Correct 477 ms 35464 KB Output is correct
3 Runtime error 256 ms 69500 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 27744 KB Output is correct
2 Correct 29 ms 27796 KB Output is correct
3 Correct 29 ms 28024 KB Output is correct
4 Correct 29 ms 27776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1112 ms 35844 KB Output is correct
2 Correct 821 ms 35240 KB Output is correct
3 Runtime error 222 ms 69560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2743 ms 36240 KB Output is correct
2 Correct 3283 ms 36188 KB Output is correct
3 Correct 2066 ms 35316 KB Output is correct
4 Runtime error 228 ms 69600 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -