Submission #771410

#TimeUsernameProblemLanguageResultExecution timeMemory
771410gggkik철도 요금 (JOI16_ho_t3)C++14
100 / 100
145 ms29800 KiB
#include <bits/stdc++.h> using namespace std; const int MXN = 2e5+5; using pii = pair<int,int>; pii d[MXN]; vector<pii> E[MXN]; int ans[MXN], n, m, q; void dijkstra(int s){ priority_queue<pair<pii,int>> pq; for(int i = 1;i<=n;i++) d[i] = {1<<30,1<<30}; d[s] = {0,q+1}; pq.push({{0,q+1},s}); for(;pq.size();){ int di = -pq.top().first.first, ci = pq.top().first.second, x = pq.top().second; pq.pop(); if(d[x]!=pii{di,ci}) continue; for(auto &i : E[x]) if(pii{d[i.first].first,-d[i.first].second}>pii{di+1,-min(ci,i.second)}){ d[i.first] = {di+1,min(ci,i.second)}; pq.push({{-di-1,min(ci,i.second)},i.first}); } } } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m >> q; vector<vector<int>> edges; for(int i = 0;i<m;i++){ int a,b; cin >> a >> b; edges.push_back({a,b}); } for(int i = 1;i<=q;i++){ int a; cin >> a; edges[a-1].push_back(i); } for(auto &i : edges){ if(i.size()==2) i.push_back(q+1); E[i[0]].push_back({i[1],i[2]}); E[i[1]].push_back({i[0],i[2]}); } dijkstra(1); for(int i = 1;i<=n;i++) { ans[d[i].second]++; } for(int i = 1;i<=q;i++) { ans[i] += ans[i-1]; cout << ans[i] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...