# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647555 | ToroTN | Cities (BOI16_cities) | C++14 | 6095 ms | 43820 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define X first
#define Y second
ll n,k,m,node[5],u_i,v_i,w_i,d[32][100005],u,num,dp[32],pow_2[5],mn=1e18;
vector<pair<ll,ll> > g[100005];
vector<ll> bit[6];
priority_queue<pair<ll,ll> > pq;
void dij(ll arr[])
{
for(int i=1;i<=n;i++)
{
pq.push({-arr[i],i});
}
while(!pq.empty())
{
u=pq.top().second;
pq.pop();
for(auto [y,cost]:g[u])
{
if(arr[u]+cost<arr[y])
{
arr[y]=arr[u]+cost;
pq.push({-arr[y],y});
}
}
}
}
int main()
{
pow_2[0]=1;
for(int i=1;i<=4;i++)
{
pow_2[i]=pow_2[i-1]*2;
}
scanf("%lld%lld%lld",&n,&num,&m);
for(int i=1;i<=num;i++)
{
scanf("%lld",&node[i-1]);
}
for(int i=1;i<=m;i++)
{
scanf("%lld%lld%lld",&u_i,&v_i,&w_i);
g[u_i].pb({v_i,w_i});
g[v_i].pb({u_i,w_i});
}
for(int i=0;i<32;i++)
{
for(int j=1;j<=n;j++)
{
d[i][j]=1e18;
}
}
for(int i=0;i<num;i++)
{
d[pow_2[i]][node[i]]=0;
dij(d[pow_2[i]]);
}
for(int i=0;i<32;i++)
{
ll kmp=0;
for(int j=0;j<=4;j++)
{
if((i|pow_2[j])==i)++kmp;
}
bit[kmp].pb(i);
}
// for(int i=1;i<=n;i++)
// {
// printf("%lld ",d[1][i]);
// }
// printf("\n");
for(int i=2;i<=num;i++)
{
for(int j=1;j<=i/2;j++)
{
for(auto k:bit[i-j])
{
for(auto l:bit[j])
{
if(k!=l)
{
for(int c=1;c<=n;c++)
{
d[(k|l)][c]=d[k][c]+d[l][c];
}
dij(d[(k|l)]);
}
}
}
}
}
for(int i=1;i<=n;i++)
{
mn=min(mn,d[pow_2[num]-1][i]);
}
printf("%lld\n",mn);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |