# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
56182 |
2018-07-10T07:47:04 Z |
노영훈(#1580) |
Cities (BOI16_cities) |
C++11 |
|
1442 ms |
62428 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;
const ll linf=2e18;
struct edge{
int to; ll co;
bool operator < (const edge &e) const {
return co>e.co;
}
};
vector<edge> G0[MX], G1[MX*6];
int n, m, k;
int A[6];
ll dist[6][MX];
ll solve3(){
ll ans=linf;
for(int i=1; i<=n; i++){
ll now=0;
for(int j=1; j<=k; j++) now+=dist[j][i];
ans=min(ans, now);
}
return ans;
}
ll S[MX];
ll ans[MX];
priority_queue<edge> Q;
ll doit(ll A[], ll B[]){
int s=0, e=2*n+2;
for(int i=s; i<=e; i++) G1[i].clear();
for(int i=1; i<=n; i++){
G1[0].push_back({i*2, A[i]+B[i]});
G1[i*2+1].push_back({e, S[i]-A[i]-B[i]});
for(edge &e:G0[i]){
int x=e.to; ll c=e.co;
G1[i*2].push_back({x*2+1, c});
G1[i*2].push_back({x*2, c});
}
G1[i*2].push_back({i*2+1, 0});
}
fill(ans, ans+e+1, linf);
while(!Q.empty()) Q.pop();
ans[s]=0; Q.push({s,0});
while(!Q.empty()){
int v=Q.top().to; ll d=Q.top().co; Q.pop();
if(ans[v]!=d) continue;
for(edge &e:G1[v]){
int x=e.to; ll c=e.co;
if(d+c>=ans[x]) continue;
ans[x]=d+c; Q.push({x,ans[x]});
}
}
// for(int i=1; i<=n; i++) cout<<ans[i*2+1]<<' ';
// cout<<'\n';
return ans[e];
}
ll solve4(){
ll ans=solve3();
for(int i=1; i<=n; i++) S[i]=dist[1][i]+dist[2][i]+dist[3][i]+dist[4][i];
ans=min({doit(dist[1], dist[2]), doit(dist[1], dist[3]), doit(dist[1], dist[4])});
return ans;
}
ll solve5(){
return 0;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>k>>m;
for(int i=1; i<=k; i++) cin>>A[i];
for(int i=1; i<=m; i++){
int u,v,c; cin>>u>>v>>c;
G0[u].push_back({v,c});
G0[v].push_back({u,c});
}
for(int i=1; i<=k; i++){
int st=A[i];
ll *D=dist[i];
for(int i=1; i<=n; i++) D[i]=linf;
priority_queue<edge> Q;
D[st]=0; Q.push({st, 0});
while(!Q.empty()){
int v=Q.top().to; ll d=Q.top().co; Q.pop();
if(D[v]!=d) continue;
for(edge &e:G0[v]){
int x=e.to; ll c=e.co;
if(d+c>=D[x]) continue;
D[x]=d+c; Q.push({x,D[x]});
}
}
// for(int i=1; i<=n; i++) cout<<D[i]<<' ';
// cout<<'\n';
}
if(k<=3) cout<<solve3();
else if(k<=4) cout<<solve4();
else cout<<solve5();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16760 KB |
Output is correct |
2 |
Correct |
16 ms |
16896 KB |
Output is correct |
3 |
Correct |
15 ms |
17072 KB |
Output is correct |
4 |
Correct |
15 ms |
17072 KB |
Output is correct |
5 |
Incorrect |
15 ms |
17072 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
346 ms |
31528 KB |
Output is correct |
2 |
Correct |
372 ms |
32068 KB |
Output is correct |
3 |
Correct |
199 ms |
32068 KB |
Output is correct |
4 |
Correct |
137 ms |
32068 KB |
Output is correct |
5 |
Correct |
318 ms |
32068 KB |
Output is correct |
6 |
Correct |
108 ms |
32068 KB |
Output is correct |
7 |
Correct |
17 ms |
32068 KB |
Output is correct |
8 |
Correct |
19 ms |
32068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
32068 KB |
Output is correct |
2 |
Correct |
23 ms |
32068 KB |
Output is correct |
3 |
Correct |
22 ms |
32068 KB |
Output is correct |
4 |
Correct |
21 ms |
32068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1442 ms |
62428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
666 ms |
62428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |