# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
544948 | 2022-04-03T08:09:33 Z | MilosMilutinovic | Cities (BOI16_cities) | C++14 | 6000 ms | 35712 KB |
#include<bits/stdc++.h> #define fi first #define se second #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; template<typename T> bool chkmin(T&x,T y){return x<y?x=y,1:0;} template<typename T> bool chkmax(T&x,T y){return x>y?x=y,1:0;} const ll inf=(ll)1e18; int n,k,m,id[100005]; ll dist[100005][1<<5]; vector<pii> g[100005]; priority_queue<pair<ll,int>> que; void dijkstra(int mask){ for(int i=1;i<=n;i++)if(dist[i][mask]!=inf)que.push(mp(dist[i][mask],i)); while(!que.empty()){ ll d=que.top().first; int u=que.top().second; que.pop(); if(dist[u][mask]<d)continue; for(auto e:g[u]){ int v=e.first,w=e.second; if(dist[v][mask]>dist[u][mask]+w){ dist[v][mask]=dist[u][mask]+w; que.push(mp(dist[v][mask],v)); } } } } int main(){ scanf("%d%d%d",&n,&k,&m); for(int i=1;i<=n;i++)id[i]=-1; for(int i=1;i<=n;i++)for(int j=0;j<(1<<k);j++)dist[i][j]=inf; for(int i=1;i<=k;i++){ int x;scanf("%d",&x); id[x]=i-1; dist[x][1<<(i-1)]=0; } for(int i=1;i<=m;i++){ int u,v,w;scanf("%d%d%d",&u,&v,&w); g[u].pb(mp(v,w)); g[v].pb(mp(u,w)); } for(int mask=1;mask<(1<<k);mask++){ if(__builtin_popcount(mask)>1){ for(int s=((mask-1)&mask);s>0;s=((s-1)&mask)){ for(int i=1;i<=n;i++)dist[i][mask]=min(dist[i][mask],dist[i][s]+dist[i][mask^s]); } } dijkstra(mask); } ll ans=inf; for(int i=1;i<=n;i++)ans=min(ans,dist[i][(1<<k)-1]); printf("%lld",ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2772 KB | Output is correct |
2 | Correct | 1 ms | 2644 KB | Output is correct |
3 | Correct | 2 ms | 2644 KB | Output is correct |
4 | Correct | 2 ms | 2660 KB | Output is correct |
5 | Correct | 2 ms | 2644 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 6092 ms | 35712 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 98 ms | 3020 KB | Output is correct |
2 | Correct | 17 ms | 3028 KB | Output is correct |
3 | Correct | 36 ms | 2980 KB | Output is correct |
4 | Correct | 31 ms | 2772 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 6011 ms | 35672 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 6102 ms | 35652 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |