Submission #503457

#TimeUsernameProblemLanguageResultExecution timeMemory
50345779brue철도 요금 (JOI16_ho_t3)C++14
100 / 100
190 ms21444 KiB
#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)

2016_ho_t3.cpp: In function 'int main()':
2016_ho_t3.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     scanf("%d %d %d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
2016_ho_t3.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
2016_ho_t3.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         scanf("%d", &pnt);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...