Submission #1059433

# Submission time Handle Problem Language Result Execution time Memory
1059433 2024-08-15T00:29:49 Z vjudge1 Cities (BOI16_cities) C++17
74 / 100
5297 ms 262144 KB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod=1e9+7;
const int M=2e5+10;
int n,m,k,f[M][1<<6];
vector<ii> ke[M];
struct node
{
  int u,mask,val;
};
struct cmp
{
  bool operator() (node a,node b) {
    return a.val>b.val;
  }
};
priority_queue<node,vector<node> ,cmp> h;
int tmp[1<<5];
void dij()
{
  while(!h.empty())
  {
    node u=h.top();h.pop();

    //cout << u.u << " " << u.mask << " " << u.val << "\n";
    for(ii v:ke[u.u])
    {
      fori(i,0,(1<<k)-1) tmp[i|u.mask]=min(tmp[i|u.mask],u.val+f[v.fi][i]+v.se);
      fori(i,0,(1<<k)-1)
      {
        if(tmp[i]<f[v.fi][i])
        {
          f[v.fi][i]=tmp[i];
          h.push({v.fi,i,f[v.fi][i]});
        }
        tmp[i]=1e18;
      }
    }
  }
}
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  #define task "1"
  if(fopen(task".inp","r"))
  {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }
  cin >> n >> k >> m;
  fori(i,1,n)
  {
    fori(j,1,(1<<k)-1) f[i][j]=1e18;
  }
  fori(i,1,(1<<k)-1) tmp[i]=1e18;
  fori(i,0,k-1)
  {
    int x;
    cin >> x;
    h.push({x,1<<i,0});
    f[x][1<<i]=0;
  }
  fori(i,1,m)
  {
    int u,v,w;
    cin >> u >> v >> w;
    ke[u].pb({v,w});
    ke[v].pb({u,w});
  }
  dij();
  int kq=1e18;
  fori(i,1,n) kq=min(kq,f[i][(1<<k)-1]);
  cout << kq;
}


Compilation message

cities.cpp: In function 'int32_t main()':
cities.cpp:55:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
cities.cpp:56:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6792 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 2 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1062 ms 94376 KB Output is correct
2 Correct 944 ms 93712 KB Output is correct
3 Correct 272 ms 68800 KB Output is correct
4 Correct 457 ms 20760 KB Output is correct
5 Correct 291 ms 76024 KB Output is correct
6 Correct 101 ms 20068 KB Output is correct
7 Correct 4 ms 7200 KB Output is correct
8 Correct 2 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 7764 KB Output is correct
2 Correct 11 ms 7832 KB Output is correct
3 Correct 4 ms 7124 KB Output is correct
4 Correct 11 ms 7768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5297 ms 168276 KB Output is correct
2 Correct 4899 ms 167692 KB Output is correct
3 Correct 1536 ms 87204 KB Output is correct
4 Correct 4070 ms 94100 KB Output is correct
5 Correct 1689 ms 48208 KB Output is correct
6 Correct 1831 ms 24312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 915 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -