# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1059440 |
2024-08-15T00:51:00 Z |
vjudge1 |
Cities (BOI16_cities) |
C++17 |
|
6000 ms |
194704 KB |
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define ii pair<int,long long >
#define fi first
#define se second
#define pb push_back
using namespace std;
const int M=1e5+10;
int n,m,k;
long long f[M][1<<6];
vector<ii> ke[M];
#define node tuple<long long ,int ,int >
priority_queue<node,vector<node> ,greater<node> > h;
long long tmp[1<<6];
void dij()
{
while(!h.empty())
{
auto [val,mask,u]=h.top();h.pop();
if(f[u][mask]<val) continue;
for(ii v:ke[u])
{
fori(i,0,(1<<k)-1) tmp[i|mask]=min(tmp[i|mask],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({f[v.fi][i],i,v.fi});
}
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({0,1<<i,x});
f[x][1<<i]=0;
}
fori(i,1,m)
{
long long u,v,w;
cin >> u >> v >> w;
ke[u].pb({v,w});
ke[v].pb({u,w});
}
dij();
long long 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:44:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
cities.cpp:45:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4856 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
653 ms |
79564 KB |
Output is correct |
2 |
Correct |
581 ms |
78856 KB |
Output is correct |
3 |
Correct |
242 ms |
62404 KB |
Output is correct |
4 |
Correct |
74 ms |
14552 KB |
Output is correct |
5 |
Correct |
223 ms |
67272 KB |
Output is correct |
6 |
Correct |
41 ms |
14020 KB |
Output is correct |
7 |
Correct |
3 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5340 KB |
Output is correct |
2 |
Correct |
7 ms |
5340 KB |
Output is correct |
3 |
Correct |
4 ms |
5080 KB |
Output is correct |
4 |
Correct |
6 ms |
5344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2209 ms |
128884 KB |
Output is correct |
2 |
Correct |
1908 ms |
127976 KB |
Output is correct |
3 |
Correct |
943 ms |
74668 KB |
Output is correct |
4 |
Correct |
1268 ms |
71228 KB |
Output is correct |
5 |
Correct |
343 ms |
36152 KB |
Output is correct |
6 |
Correct |
198 ms |
18128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6065 ms |
194704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |