제출 #1245828

#제출 시각아이디문제언어결과실행 시간메모리
1245828vuxxcodeCities (BOI16_cities)C++20
100 / 100
4145 ms65588 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define pl pair<ll,ll>
#define ve vector
#define vi ve<int>
#define vvi ve<vi>
#define vl ve<ll>
#define vii ve<ii>
#define all(x) x.begin(), x.end()
#define fo(i,a,b) for (int i=(a),_b=(b); i<=_b; ++i)
#define fd(i,a,b) for (int i=(a),_b=(b); i>=_b; --i)
#define lc p+1
#define rc p+(mid-l+1)*2
#define maxi(a, b) a = max(a, b)
#define mini(a, b) a = min(a, b)
#define bit(s, i) (((s) >> (i)) & 1)
#define tup3 array<int,3>
#define tup4 array<int,4>
#define matrix vvi
#define cntBit(x) (__builtin_popcountll(x))
#define SZ(x) int(x.size())
#define x1 _
#define x2 __
#define y1 _
#define y2 __

const int N = 1e5+5, M = 1e6+5;
const int inf = 1e9+10;
const int mod = 1e9+7;
const int LG = 20, base=11111, B = 500;
bool st_mem;

int n, k, m;
ve<ii> g[N];
ll d[N][1<<6];

void sol() {
    cin >> n >> k >> m;
    vi v(k);
    fo(i,0,k-1) cin >> v[i];
    fo(i,1,m) {
        int u, v, c; cin >> u >> v >> c;
        g[u].eb(v, c), g[v].eb(u, c);
    }
    struct node {
        int u; ll d;
        bool operator < (const node &o) const {
            return d > o.d;
        }
    };
    memset(d,0x3f,sizeof(d));
    fo(i,1,n) d[i][0]=0;
    fo(i,0,k-1) {
        d[v[i]][1<<i]=0;
    }
    ll ans=1e18;
    fo(mask,1,(1<<k)-1) {
        priority_queue<node> q;
        fo(i,1,n) {
            fo(j,0,(1<<k)-1) {
                fo(l,0,(1<<k)-1) if ((j|l)==mask)
                    mini(d[i][mask], d[i][j]+d[i][l]);
            }
        }
        fo(i,1,n) if (d[i][mask] < 1e18) q.push({i,d[i][mask]});
        while (q.size()) {
            node t = q.top(); q.pop();
            int u = t.u; ll dd = t.d;
            if (d[u][mask]^dd) continue;
            for (ii &x:g[u]) {
                int v=x.fi, c=x.se;
                if (d[v][mask]>dd+c) {
                    d[v][mask]=dd+c;
                    q.push({v,dd+c});
                }
            }
        }
    }
    fo(i,1,n) mini(ans, d[i][(1<<k)-1]);
    cout << ans;
}

bool en_mem;
signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    if(fopen("A.inp","r")) {
        freopen("A.inp","r",stdin);
        freopen("A.out","w",stdout);
    }
    int tc = 1; // cin >> tc;
    fo(i,1,tc) sol();
     // cerr << abs(&en_mem - &st_mem) / 1024.0 / 1024.0;
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

cities.cpp: In function 'int main()':
cities.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen("A.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~
cities.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen("A.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...