Submission #572171

# Submission time Handle Problem Language Result Execution time Memory
572171 2022-06-03T21:38:40 Z groshi Cities (BOI16_cities) C++17
100 / 100
2613 ms 49792 KB
#include<iostream>
#include<vector>
#include<queue>
#include<utility>
using namespace std;
#define int long long
struct wi{
    vector<int> Q;
    long long dp[35];
    bool odw=0;
}*w;
int32_t main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int n,k,m,x,y,z;
    cin>>n>>k>>m;
    w=new wi[n+3];
    for(int i=1;i<=n;i++)
        for(int j=0;j<=32;j++)
            w[i].dp[j]=1e18;
    for(int i=0;i<k;i++)
    {
        int x;
        cin>>x;
        w[x].dp[1<<i]=0;
    }
    for(int i=1;i<=m;i++)
    {
        cin>>x>>y>>z;
        w[x].Q.push_back(y);
        w[x].Q.push_back(z);
        w[y].Q.push_back(x);
        w[y].Q.push_back(z);
    }
    priority_queue<pair<long long,int> > kolejka;
    for(int i=1;i<(1<<k);i++)
    {
        for(int pom=1;pom<i;pom++)
        {
            if((pom|i)!=i)
                continue;
            int pom2=i^pom;
            if(pom>pom2)
                continue;
            for(int j=1;j<=n;j++)
                w[j].dp[i]=min(w[j].dp[i],w[j].dp[pom]+w[j].dp[pom2]);
        }
        for(int j=1;j<=n;j++)
            w[j].odw=0;
        for(int j=1;j<=n;j++)
        {
            if(w[j].dp[i]==1e18)
                continue;
            kolejka.emplace(-w[j].dp[i],j);
        }
        while(!kolejka.empty())
        {
            pair<long long,int> para=kolejka.top();
            kolejka.pop();
            if(w[para.second].odw)
                continue;
            //cout<<i<<": "<<-para.first<<" "<<para.second<<"\n";
            w[para.second].odw=1;
            for(int j=0;j<w[para.second].Q.size();j+=2)
            {
                int kto=w[para.second].Q[j];
                long long ile=-para.first+w[para.second].Q[j+1];
                if(ile<w[kto].dp[i])
                {
                kolejka.emplace(-ile,kto);
                w[kto].dp[i]=ile;
                }
            }
        }
    }
    long long wynik=1e18;
    for(int i=1;i<=n;i++)
        wynik=min(wynik,w[i].dp[(1<<k)-1]);
    cout<<wynik;
    return 0;
}

Compilation message

cities.cpp: In function 'int32_t main()':
cities.cpp:66:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             for(int j=0;j<w[para.second].Q.size();j+=2)
      |                         ~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 617 ms 49576 KB Output is correct
2 Correct 615 ms 48696 KB Output is correct
3 Correct 351 ms 40384 KB Output is correct
4 Correct 65 ms 13000 KB Output is correct
5 Correct 326 ms 49792 KB Output is correct
6 Correct 61 ms 13092 KB Output is correct
7 Correct 3 ms 844 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 724 KB Output is correct
2 Correct 5 ms 832 KB Output is correct
3 Correct 3 ms 680 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1283 ms 49652 KB Output is correct
2 Correct 1253 ms 48708 KB Output is correct
3 Correct 831 ms 40388 KB Output is correct
4 Correct 704 ms 32444 KB Output is correct
5 Correct 176 ms 16668 KB Output is correct
6 Correct 67 ms 15088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2613 ms 49644 KB Output is correct
2 Correct 2585 ms 49596 KB Output is correct
3 Correct 2548 ms 48744 KB Output is correct
4 Correct 1782 ms 40292 KB Output is correct
5 Correct 1356 ms 32476 KB Output is correct
6 Correct 250 ms 16704 KB Output is correct
7 Correct 85 ms 15236 KB Output is correct