답안 #503457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503457 2022-01-08T04:27:42 Z 79brue 철도 요금 (JOI16_ho_t3) C++14
100 / 100
190 ms 21444 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();
            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

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);
      |         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 5208 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 3 ms 5068 KB Output is correct
6 Correct 4 ms 5036 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 2 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 5208 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 3 ms 5068 KB Output is correct
6 Correct 4 ms 5036 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 2 ms 4940 KB Output is correct
9 Correct 101 ms 16544 KB Output is correct
10 Correct 99 ms 16560 KB Output is correct
11 Correct 92 ms 16036 KB Output is correct
12 Correct 96 ms 16104 KB Output is correct
13 Correct 106 ms 16340 KB Output is correct
14 Correct 99 ms 16172 KB Output is correct
15 Correct 60 ms 11652 KB Output is correct
16 Correct 46 ms 10340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 16692 KB Output is correct
2 Correct 115 ms 19024 KB Output is correct
3 Correct 70 ms 16960 KB Output is correct
4 Correct 99 ms 18564 KB Output is correct
5 Correct 98 ms 18508 KB Output is correct
6 Correct 100 ms 18616 KB Output is correct
7 Correct 50 ms 11540 KB Output is correct
8 Correct 51 ms 11416 KB Output is correct
9 Correct 35 ms 12144 KB Output is correct
10 Correct 33 ms 13304 KB Output is correct
11 Correct 126 ms 18584 KB Output is correct
12 Correct 109 ms 17992 KB Output is correct
13 Correct 101 ms 17720 KB Output is correct
14 Correct 117 ms 18936 KB Output is correct
15 Correct 125 ms 18068 KB Output is correct
16 Correct 121 ms 17340 KB Output is correct
17 Correct 129 ms 17476 KB Output is correct
18 Correct 86 ms 12612 KB Output is correct
19 Correct 160 ms 20960 KB Output is correct
20 Correct 135 ms 17472 KB Output is correct
21 Correct 73 ms 11952 KB Output is correct
22 Correct 79 ms 11840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 5208 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 3 ms 5068 KB Output is correct
6 Correct 4 ms 5036 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 2 ms 4940 KB Output is correct
9 Correct 101 ms 16544 KB Output is correct
10 Correct 99 ms 16560 KB Output is correct
11 Correct 92 ms 16036 KB Output is correct
12 Correct 96 ms 16104 KB Output is correct
13 Correct 106 ms 16340 KB Output is correct
14 Correct 99 ms 16172 KB Output is correct
15 Correct 60 ms 11652 KB Output is correct
16 Correct 46 ms 10340 KB Output is correct
17 Correct 108 ms 16692 KB Output is correct
18 Correct 115 ms 19024 KB Output is correct
19 Correct 70 ms 16960 KB Output is correct
20 Correct 99 ms 18564 KB Output is correct
21 Correct 98 ms 18508 KB Output is correct
22 Correct 100 ms 18616 KB Output is correct
23 Correct 50 ms 11540 KB Output is correct
24 Correct 51 ms 11416 KB Output is correct
25 Correct 35 ms 12144 KB Output is correct
26 Correct 33 ms 13304 KB Output is correct
27 Correct 126 ms 18584 KB Output is correct
28 Correct 109 ms 17992 KB Output is correct
29 Correct 101 ms 17720 KB Output is correct
30 Correct 117 ms 18936 KB Output is correct
31 Correct 125 ms 18068 KB Output is correct
32 Correct 121 ms 17340 KB Output is correct
33 Correct 129 ms 17476 KB Output is correct
34 Correct 86 ms 12612 KB Output is correct
35 Correct 160 ms 20960 KB Output is correct
36 Correct 135 ms 17472 KB Output is correct
37 Correct 73 ms 11952 KB Output is correct
38 Correct 79 ms 11840 KB Output is correct
39 Correct 190 ms 21444 KB Output is correct
40 Correct 164 ms 21428 KB Output is correct
41 Correct 96 ms 17824 KB Output is correct
42 Correct 150 ms 21044 KB Output is correct
43 Correct 163 ms 21064 KB Output is correct
44 Correct 161 ms 20952 KB Output is correct
45 Correct 166 ms 21004 KB Output is correct
46 Correct 78 ms 13484 KB Output is correct
47 Correct 80 ms 12732 KB Output is correct
48 Correct 79 ms 12592 KB Output is correct
49 Correct 69 ms 12552 KB Output is correct
50 Correct 62 ms 13776 KB Output is correct
51 Correct 65 ms 13092 KB Output is correct
52 Correct 66 ms 14424 KB Output is correct
53 Correct 59 ms 12432 KB Output is correct
54 Correct 58 ms 13764 KB Output is correct