Submission #69876

# Submission time Handle Problem Language Result Execution time Memory
69876 2018-08-21T18:29:39 Z Bodo171 Cities (BOI16_cities) C++14
74 / 100
6000 ms 172884 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,orig;
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;orig=(((1<<k)-1)^stare);
            for(i=orig;i!=0;i=((i-1)&orig))
            {
                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 3 ms 2792 KB Output is correct
3 Correct 4 ms 2868 KB Output is correct
4 Correct 4 ms 2892 KB Output is correct
5 Correct 5 ms 2892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 624 ms 57912 KB Output is correct
2 Correct 647 ms 57912 KB Output is correct
3 Correct 195 ms 57912 KB Output is correct
4 Correct 132 ms 57912 KB Output is correct
5 Correct 309 ms 57912 KB Output is correct
6 Correct 129 ms 57912 KB Output is correct
7 Correct 7 ms 57912 KB Output is correct
8 Correct 7 ms 57912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 57912 KB Output is correct
2 Correct 10 ms 57912 KB Output is correct
3 Correct 7 ms 57912 KB Output is correct
4 Correct 9 ms 57912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2198 ms 74696 KB Output is correct
2 Correct 1957 ms 74696 KB Output is correct
3 Correct 1296 ms 74696 KB Output is correct
4 Correct 1339 ms 74696 KB Output is correct
5 Correct 292 ms 74696 KB Output is correct
6 Correct 144 ms 74696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6056 ms 172884 KB Time limit exceeded
2 Halted 0 ms 0 KB -