# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
335803 | ChrisT | 철도 요금 (JOI16_ho_t3) | C++17 | 240 ms | 21868 KiB |
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 MN = 1e5 + 5;
vector<array<int,2>> adj[MN];
vector<array<int,2>> dagadj[MN];
int indeg[MN], ed[MN*2], dist[MN];
bool exists[MN*2];
int main() {
int n,m,qq;
scanf ("%d %d %d",&n,&m,&qq);
vector<array<int,2>> edges(m+1);
for (int i = 1; i <= m; i++) {
scanf ("%d %d",&edges[i][0],&edges[i][1]);
adj[edges[i][0]].push_back({edges[i][1],i});
adj[edges[i][1]].push_back({edges[i][0],i});
}
memset(dist,0x3f,sizeof dist);
queue<int> q; dist[1] = 0; q.push(1);
while (!q.empty()) {
int cur = q.front(); q.pop();
for (auto &[u,i] : adj[cur]) {
if (dist[cur] + 1 < dist[u]) {
dist[u] = dist[cur] + 1;
q.push(u); ed[i] = u; indeg[u] = 1;
dagadj[cur].push_back({u,i});
} else if (dist[cur] + 1 == dist[u]) {
ed[i] = u; ++indeg[u]; dagadj[cur].push_back({u,i});
}
}
}
fill(exists+1,exists+m+1,true);
int ans = n;
for (int t = 1; t <= qq; t++) {
int r; scanf ("%d",&r);
if (exists[r] && ed[r] && !(--indeg[ed[r]])) q.push(ed[r]), --ans;
exists[r] = 0;
while (!q.empty()) {
int cur = q.front(); q.pop();
for (auto &[u,i] : dagadj[cur]) {
if (exists[i] && !(--indeg[u])) {
--ans; q.push(u);
}
exists[i] = 0;
}
}
printf ("%d\n",n-ans);
}
return 0;
}
Compilation message (stderr)
# | 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... |