제출 #361510

#제출 시각아이디문제언어결과실행 시간메모리
361510cpp219Cities (BOI16_cities)C++14
0 / 100
747 ms53280 KiB
#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #define ll long long #define ld long double #define fs first #define sc second using namespace std; const ll N = 2e5 + 69; const ll inf = 1e16 + 7; typedef pair<ll,ll> LL; vector<LL> g[N]; ll n,k,m,a[N],c,x,y,D[10][N],d[N],dp[N],ans = inf; ll b[N]; void Dij(ll scr){ set<LL> s; fill(d,d + n + 1,inf); s.insert({0,a[scr]}); d[a[scr]] = 0; while(!s.empty()){ LL t = *s.begin(); s.erase(s.begin()); ll u = t.sc; for (auto i : g[u]){ ll v = i.fs,L = i.sc; if (d[v] > d[u] + L){ s.erase({d[v],v}); d[v] = d[u] + L; s.insert({d[v],v}); } } } for (ll i = 1;i <= n;i++) D[scr][i] = d[i]; } bool chkbit(ll x,ll i){ return (x >> i) & 1; } bool chkmask(ll mask,ll now){ ll p = mask & now; return !p; } ll cal(ll mask,ll ver){ ll res = 0; for (ll i = 1;i <= k;i++) if (chkbit(mask,i - 1)) res += D[i][ver]; return res; } ll f(ll mask){ //cout<<mask<<"\n"; if (mask == (1 << k) - 1) return 0; if (dp[mask] != -1) return dp[mask]; ll kq = inf; for (ll i = 0;i < k;i++){ if (chkbit(mask,i)){ for (ll j = 1;j <= n;j++){ for (ll l = 1;l <= (1 << k) - 1;l++){ if (chkmask(mask,l)){ kq = min(kq,cal(l,j) + D[i + 1][j] + f(mask | l)); } } } } } return dp[mask] = kq; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "tst" if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } cin>>n>>k>>m; for (ll i = 1;i <= k;i++) cin>>a[i]; while(m--){ cin>>x>>y>>c; g[x].push_back({y,c}); g[y].push_back({x,c}); } for (ll i = 1;i <= n;i++) Dij(i); memset(dp,-1,sizeof(dp)); cout<<f(1); }

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

cities.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
cities.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
cities.cpp: In function 'int main()':
cities.cpp:82:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   82 |     for (ll i = 1;i <= n;i++) Dij(i); memset(dp,-1,sizeof(dp));
      |     ^~~
cities.cpp:82:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   82 |     for (ll i = 1;i <= n;i++) Dij(i); memset(dp,-1,sizeof(dp));
      |                                       ^~~~~~
cities.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   73 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...