# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
503457 | 79brue | 철도 요금 (JOI16_ho_t3) | C++14 | 190 ms | 21444 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;
typedef long long ll;
struct Edge{
int s, e, x;
Edge(){}
Edge(int s, int e, int x): s(s), e(e), x(x){}
};
int n, m, q;
bool edgeValid[200002];
Edge arr[200002];
vector<Edge> link[200002];
int dist[200002];
int ans;
int indeg[200002];
bool edgeVisited[200002];
void bfs(){
vector<bool> visited (n+10);
visited[1] = 1;
queue<int> que; que.push(1);
while(!que.empty()){
int x = que.front(); que.pop();
for(auto y: link[x]){
if(visited[y.e]) continue;
visited[y.e] = 1;
dist[y.e] = dist[y.s] + 1;
que.push(y.e);
}
}
for(int i=1; i<=n; i++){
vector<Edge> vec;
for(auto y: link[i]){
if(dist[y.s] + 1 == dist[y.e]) vec.push_back(y);
}
link[i] = vec;
}
}
int main(){
scanf("%d %d %d", &n, &m, &q);
for(int i=1; i<=m; i++){
int x, y;
scanf("%d %d", &x, &y);
link[x].push_back(Edge(x, y, i));
link[y].push_back(Edge(y, x, i));
arr[i] = Edge(x, y, i);
edgeValid[i] = 1;
}
bfs();
for(int i=1; i<=m; i++){
if(dist[arr[i].s] == dist[arr[i].e]) edgeValid[i] = 0;
else{
if(dist[arr[i].s] > dist[arr[i].e]) swap(arr[i].s, arr[i].e);
indeg[arr[i].e]++;
}
}
for(int i=1; i<=q; i++){
int pnt;
scanf("%d", &pnt);
if(!edgeValid[pnt] || edgeVisited[pnt]){
printf("%d\n", ans);
continue;
}
queue<int> que;
que.push(pnt);
while(!que.empty()){
int e = que.front(); que.pop();
edgeVisited[e] = 1;
indeg[arr[e].e]--;
if(!indeg[arr[e].e]){
ans++;
for(Edge p: link[arr[e].e]){
if(edgeVisited[p.x]) continue;
que.push(p.x);
}
}
}
printf("%d\n", ans);
}
}
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... |