제출 #1123457

#제출 시각아이디문제언어결과실행 시간메모리
1123457AvianshVoting Cities (NOI22_votingcity)C++20
100 / 100
464 ms51524 KiB
#include <bits/stdc++.h> using namespace std; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n,e,k; cin >> n >> e >> k; int t[k]; for(int &i : t){ cin >> i; } vector<array<int,2>>g[n]; for(int i = 0;i<e;i++){ int a,b,c; cin >> a >> b >> c; g[b].push_back({a,c}); } int q; cin >> q; priority_queue<array<long long,3>,vector<array<long long,3>>,greater<array<long long,3>>>pq; long long dist[n][32]; bool vis[n][32]; for(int i = 0;i<n;i++){ fill(dist[i],dist[i]+32,2e18); fill(vis[i],vis[i]+32,0); } //distance,loc,mask for(int i : t){ for(int mask = 0;mask<32;mask++){ pq.push({0,i,mask}); } } while(!pq.empty()){ array<long long,3>curr = pq.top(); pq.pop(); if(vis[curr[1]][curr[2]]){ continue; } dist[curr[1]][curr[2]]=curr[0]; vis[curr[1]][curr[2]]=1; for(array<int,2>v:g[curr[1]]){ for(int i = 0;i<5;i++){ if(curr[2]&(1<<i)){ pq.push({1LL*curr[0]+1LL*v[1]-((1LL*v[1]*(i+1))/10),v[0],curr[2]^(1<<i)}); } } pq.push({curr[0]+v[1],v[0],curr[2]}); } } while(q--){ int s; int p[5]; cin >> s >> p[0] >> p[1] >> p[2] >> p[3] >> p[4]; long long ans = 2e18; for(int mask = 0;mask<32;mask++){ //0 means using long long cur = dist[s][mask]; bool wor = 1; for(int i = 0;i<5;i++){ if(!((1<<i)&mask)){ if(p[i]==-1){ wor=0; break; } } } if(!wor) continue; for(int i = 0;i<5;i++){ if(!((1<<i)&mask)){ cur+=p[i]; } } ans=min(cur,ans); } if(ans==2e18){ cout << -1 << "\n"; } else{ cout << ans << "\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...