This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |