Submission #69875

# Submission time Handle Problem Language Result Execution time Memory
69875 2018-08-21T18:26:09 Z Bodo171 Cities (BOI16_cities) C++14
74 / 100
6000 ms 174872 KB
#include <iostream>
#include <fstream>
#include <queue>
#include <vector>
#include <climits>
using namespace std;
const int nmax=100005;
vector< pair<int,long long> > v[nmax];
long long d[nmax][32];
bool E[nmax][32];
int norm[nmax],imp[10];
long long di,newd,ans;
int x,n,m,nod,k,i,j,y,z,stare,stare_noua;
struct node
{
    long long D;
    int node,state;
};
struct cmp
{
    bool operator()(node unu,node doi)
    {
        return unu.D>doi.D;
    }
};
priority_queue <node,vector<node>,cmp > pq;
void dij()
{
    while(!pq.empty())
    {
        x=pq.top().node;di=pq.top().D;stare=pq.top().state;
        pq.pop();
        if(stare==(1<<k)-1)
        {
            ans=di;
            return;
        }
        if(!E[x][stare])
        {
            E[x][stare]=1;
            for(i=0;i<v[x].size();i++)
            {
                nod=v[x][i].first;newd=v[x][i].second+di;
                if(newd<d[nod][stare])
                {
                    d[nod][stare]=newd;
                    pq.push({newd,nod,stare});
                }
            }
            nod=x;
            for(i=1;i<(1<<k);i++)
            {
                stare_noua=(stare|i);newd=1LL*d[x][stare]+d[x][i];
                if(newd<d[x][stare_noua])
                {
                    d[x][stare_noua]=newd;
                    pq.push({newd,x,stare_noua});
                }
            }
        }
    }
}
int main()
{
   // freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>k>>m;
    for(i=1;i<=k;i++)
    {
        cin>>imp[i];
        norm[imp[i]]=i;
    }
    for(i=1;i<=m;i++)
    {
        cin>>x>>y>>z;
        v[x].push_back({y,z});
        v[y].push_back({x,z});
    }
    for(i=1;i<=n;i++)
      for(j=1;j<(1<<k);j++)
         d[i][j]=1LL*1e17;
    for(i=1;i<=k;i++)
    {
        d[imp[i]][(1<<(i-1))]=0;
        pq.push({0,imp[i],(1<<(i-1))});
    }
    ans=LLONG_MAX;
    dij();
    cout<<ans;
    return 0;
}

Compilation message

cities.cpp: In function 'void dij()':
cities.cpp:41:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(i=0;i<v[x].size();i++)
                     ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 5 ms 2924 KB Output is correct
3 Correct 5 ms 2924 KB Output is correct
4 Correct 5 ms 2924 KB Output is correct
5 Correct 5 ms 2924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 750 ms 59720 KB Output is correct
2 Correct 691 ms 59720 KB Output is correct
3 Correct 237 ms 59720 KB Output is correct
4 Correct 120 ms 59720 KB Output is correct
5 Correct 358 ms 59720 KB Output is correct
6 Correct 96 ms 59720 KB Output is correct
7 Correct 7 ms 59720 KB Output is correct
8 Correct 7 ms 59720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 59720 KB Output is correct
2 Correct 12 ms 59720 KB Output is correct
3 Correct 8 ms 59720 KB Output is correct
4 Correct 10 ms 59720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2564 ms 76396 KB Output is correct
2 Correct 2158 ms 76396 KB Output is correct
3 Correct 1386 ms 76396 KB Output is correct
4 Correct 1442 ms 76396 KB Output is correct
5 Correct 308 ms 76396 KB Output is correct
6 Correct 161 ms 76396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6094 ms 174872 KB Time limit exceeded
2 Halted 0 ms 0 KB -