# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
503456 | 2022-01-08T04:25:00 Z | 79brue | None (JOI16_ho_t3) | C++14 | 119 ms | 18968 KB |
#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(); 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4940 KB | Output is correct |
2 | Correct | 2 ms | 4940 KB | Output is correct |
3 | Correct | 4 ms | 5276 KB | Output is correct |
4 | Correct | 3 ms | 4940 KB | Output is correct |
5 | Correct | 3 ms | 5080 KB | Output is correct |
6 | Correct | 3 ms | 4952 KB | Output is correct |
7 | Correct | 3 ms | 5024 KB | Output is correct |
8 | Correct | 2 ms | 4940 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4940 KB | Output is correct |
2 | Correct | 2 ms | 4940 KB | Output is correct |
3 | Correct | 4 ms | 5276 KB | Output is correct |
4 | Correct | 3 ms | 4940 KB | Output is correct |
5 | Correct | 3 ms | 5080 KB | Output is correct |
6 | Correct | 3 ms | 4952 KB | Output is correct |
7 | Correct | 3 ms | 5024 KB | Output is correct |
8 | Correct | 2 ms | 4940 KB | Output is correct |
9 | Correct | 112 ms | 18832 KB | Output is correct |
10 | Correct | 111 ms | 18968 KB | Output is correct |
11 | Correct | 94 ms | 18332 KB | Output is correct |
12 | Correct | 105 ms | 18392 KB | Output is correct |
13 | Correct | 102 ms | 18608 KB | Output is correct |
14 | Correct | 106 ms | 18568 KB | Output is correct |
15 | Correct | 65 ms | 12856 KB | Output is correct |
16 | Correct | 52 ms | 11372 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 119 ms | 18888 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4940 KB | Output is correct |
2 | Correct | 2 ms | 4940 KB | Output is correct |
3 | Correct | 4 ms | 5276 KB | Output is correct |
4 | Correct | 3 ms | 4940 KB | Output is correct |
5 | Correct | 3 ms | 5080 KB | Output is correct |
6 | Correct | 3 ms | 4952 KB | Output is correct |
7 | Correct | 3 ms | 5024 KB | Output is correct |
8 | Correct | 2 ms | 4940 KB | Output is correct |
9 | Correct | 112 ms | 18832 KB | Output is correct |
10 | Correct | 111 ms | 18968 KB | Output is correct |
11 | Correct | 94 ms | 18332 KB | Output is correct |
12 | Correct | 105 ms | 18392 KB | Output is correct |
13 | Correct | 102 ms | 18608 KB | Output is correct |
14 | Correct | 106 ms | 18568 KB | Output is correct |
15 | Correct | 65 ms | 12856 KB | Output is correct |
16 | Correct | 52 ms | 11372 KB | Output is correct |
17 | Incorrect | 119 ms | 18888 KB | Output isn't correct |
18 | Halted | 0 ms | 0 KB | - |