Submission #361276

# Submission time Handle Problem Language Result Execution time Memory
361276 2021-01-29T06:24:40 Z Killer2501 Cities (BOI16_cities) C++14
100 / 100
5325 ms 139404 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "talltree"
#define pll pair<ll, ll>
#define pii pair<ll, pll>
#define fi first
#define se second
#define ull unsigned long long
using namespace std;
const ll mod = 1e15+7;
const ll N = 2e5+5;
vector<pll> adj[N];
vector<ll> kq;
ll n, m, t, k, b[N], p, lab[N], u, v, h[N], a[N], ans, tong, d[N][32];
priority_queue< pii, vector<pii>, greater<pii> > pq;
void sol()
{
    cin >> n >> k >> m;
    for(int i = 0; i < k; i ++)cin >> a[i];
    for(int i = 1; i <= m; i ++)
    {
        ll x, y, w;
        cin >> x >> y >> w;
        adj[x].pb({w, y});
        adj[y].pb({w, x});
    }
    for(int i = 1; i <= n; i ++)
    {
        pii u;
        u.fi = 0;
        u.se.fi = i;
        u.se.se = 0;
        pq.push(u);
        for(int j = 1; j < (1<<k);j ++)d[i][j] = mod;
    }
    for(int i = 0; i < k; i ++)
    {
        d[a[i]][(1<<i)] = 0;
        pii u;
        u.fi = 0;
        u.se.fi = a[i];
        u.se.se = (1<<i);
        pq.push(u);
    }
    while(!pq.empty())
    {
        pii u = pq.top();
        pq.pop();
        if(d[u.se.fi][u.se.se] != u.fi)continue;
        if(u.se.se == (1<<k)-1)
        {
            cout << u.fi;
            return;
        }
        for(int j = 0; j < k; j ++)
        {
            t = u.se.se | (1<<j);
            if(d[u.se.fi][t] > u.fi + d[u.se.fi][(1<<j)])
            {
                d[u.se.fi][t] = u.fi + d[u.se.fi][(1<<j)];
                pii v;
                v.fi = d[u.se.fi][t];
                v.se.fi = u.se.fi;
                v.se.se = t;
                pq.push(v);
            }
        }
        for(pll x : adj[u.se.fi])
        {
            if(d[x.se][u.se.se] > u.fi + x.fi)
            {
                d[x.se][u.se.se] = u.fi + x.fi;
                pii v;
                v.fi = u.fi + x.fi;
                v.se.fi = x.se;
                v.se.se = u.se.se;
                pq.push(v);
            }
        }
    }
}
int main()
{
    if(fopen(task".inp", "r")){
       freopen(task".inp", "r", stdin);
       freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}


Compilation message

cities.cpp: In function 'int main()':
cities.cpp:86:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   86 |        freopen(task".inp", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:87:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   87 |        freopen(task".out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5100 KB Output is correct
2 Correct 3 ms 5100 KB Output is correct
3 Correct 3 ms 5100 KB Output is correct
4 Correct 3 ms 5100 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 679 ms 52816 KB Output is correct
2 Correct 685 ms 52304 KB Output is correct
3 Correct 197 ms 37856 KB Output is correct
4 Correct 78 ms 15092 KB Output is correct
5 Correct 325 ms 46816 KB Output is correct
6 Correct 73 ms 14648 KB Output is correct
7 Correct 6 ms 5740 KB Output is correct
8 Correct 5 ms 5484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 5932 KB Output is correct
2 Correct 10 ms 5936 KB Output is correct
3 Correct 7 ms 5484 KB Output is correct
4 Correct 7 ms 5612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2238 ms 89900 KB Output is correct
2 Correct 1828 ms 89252 KB Output is correct
3 Correct 1127 ms 60100 KB Output is correct
4 Correct 1166 ms 52952 KB Output is correct
5 Correct 245 ms 29180 KB Output is correct
6 Correct 86 ms 17536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5216 ms 139404 KB Output is correct
2 Correct 5325 ms 139248 KB Output is correct
3 Correct 4760 ms 138612 KB Output is correct
4 Correct 2306 ms 85032 KB Output is correct
5 Correct 2948 ms 77656 KB Output is correct
6 Correct 539 ms 28920 KB Output is correct
7 Correct 107 ms 18044 KB Output is correct