Submission #51664

# Submission time Handle Problem Language Result Execution time Memory
51664 2018-06-19T18:32:41 Z gs13105 None (JOI16_ho_t3) C++17
100 / 100
191 ms 15276 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

struct edg
{
    int y, w;
};

int ori[200010][2];
int que[200010];
int num[200010];

vector<edg> arr[100010];
int dis[100010];
int mem[100010];
const int INF = 1e8;

int res[200010];

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, m, q, i;
    scanf("%d%d%d", &n, &m, &q);
    for(i = 1; i <= m; i++)
        scanf("%d%d", &ori[i][0], &ori[i][1]);
    for(i = 1; i <= q; i++)
        scanf("%d", &que[i]);

    for(i = 1; i <= m; i++)
        num[i] = INF;
    for(i = 1; i <= q; i++)
        num[que[i]] = i;

    for(i = 1; i <= m; i++)
    {
        int x = ori[i][0];
        int y = ori[i][1];
        int w = num[i];

        arr[x].push_back({ y, w });
        arr[y].push_back({ x, w });
    }

    dis[1] = 0;
    for(i = 2; i <= n; i++)
        dis[i] = INF;

    mem[1] = INF;

    queue<int> bq;
    bq.push(1);

    while(!bq.empty())
    {
        int x = bq.front();
        int d = dis[x];
        bq.pop();

        for(edg &e : arr[x])
        {
            if(dis[e.y] < d + 1)
                continue;

            mem[e.y] = max(min(mem[x], e.w), mem[e.y]);

            if(dis[e.y] == INF)
            {
                dis[e.y] = dis[x] + 1;
                bq.push(e.y);
            }
        }
    }

    for(i = 1; i <= n; i++)
        if(mem[i] != INF)
            res[mem[i]]++;

    for(i = 1; i <= q; i++)
        res[i] += res[i - 1];

    for(i = 1; i <= q; i++)
        printf("%d\n", res[i]);
    return 0;
}

Compilation message

2016_ho_t3.cpp: In function 'int main()':
2016_ho_t3.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &n, &m, &q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
2016_ho_t3.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &ori[i][0], &ori[i][1]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2016_ho_t3.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &que[i]);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2792 KB Output is correct
3 Correct 5 ms 2988 KB Output is correct
4 Correct 5 ms 2988 KB Output is correct
5 Correct 4 ms 2988 KB Output is correct
6 Correct 4 ms 2988 KB Output is correct
7 Correct 4 ms 2988 KB Output is correct
8 Correct 4 ms 2988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2792 KB Output is correct
3 Correct 5 ms 2988 KB Output is correct
4 Correct 5 ms 2988 KB Output is correct
5 Correct 4 ms 2988 KB Output is correct
6 Correct 4 ms 2988 KB Output is correct
7 Correct 4 ms 2988 KB Output is correct
8 Correct 4 ms 2988 KB Output is correct
9 Correct 151 ms 12372 KB Output is correct
10 Correct 128 ms 12380 KB Output is correct
11 Correct 117 ms 12380 KB Output is correct
12 Correct 126 ms 12380 KB Output is correct
13 Correct 122 ms 12380 KB Output is correct
14 Correct 118 ms 12380 KB Output is correct
15 Correct 81 ms 12380 KB Output is correct
16 Correct 59 ms 12380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 12464 KB Output is correct
2 Correct 130 ms 12472 KB Output is correct
3 Correct 107 ms 12472 KB Output is correct
4 Correct 113 ms 12472 KB Output is correct
5 Correct 117 ms 12472 KB Output is correct
6 Correct 129 ms 12472 KB Output is correct
7 Correct 60 ms 12472 KB Output is correct
8 Correct 60 ms 12472 KB Output is correct
9 Correct 39 ms 12472 KB Output is correct
10 Correct 46 ms 12472 KB Output is correct
11 Correct 189 ms 12524 KB Output is correct
12 Correct 113 ms 12524 KB Output is correct
13 Correct 125 ms 12524 KB Output is correct
14 Correct 138 ms 12684 KB Output is correct
15 Correct 162 ms 12684 KB Output is correct
16 Correct 159 ms 12684 KB Output is correct
17 Correct 137 ms 12716 KB Output is correct
18 Correct 109 ms 12716 KB Output is correct
19 Correct 180 ms 15056 KB Output is correct
20 Correct 145 ms 15056 KB Output is correct
21 Correct 71 ms 15056 KB Output is correct
22 Correct 71 ms 15056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2792 KB Output is correct
3 Correct 5 ms 2988 KB Output is correct
4 Correct 5 ms 2988 KB Output is correct
5 Correct 4 ms 2988 KB Output is correct
6 Correct 4 ms 2988 KB Output is correct
7 Correct 4 ms 2988 KB Output is correct
8 Correct 4 ms 2988 KB Output is correct
9 Correct 151 ms 12372 KB Output is correct
10 Correct 128 ms 12380 KB Output is correct
11 Correct 117 ms 12380 KB Output is correct
12 Correct 126 ms 12380 KB Output is correct
13 Correct 122 ms 12380 KB Output is correct
14 Correct 118 ms 12380 KB Output is correct
15 Correct 81 ms 12380 KB Output is correct
16 Correct 59 ms 12380 KB Output is correct
17 Correct 147 ms 12464 KB Output is correct
18 Correct 130 ms 12472 KB Output is correct
19 Correct 107 ms 12472 KB Output is correct
20 Correct 113 ms 12472 KB Output is correct
21 Correct 117 ms 12472 KB Output is correct
22 Correct 129 ms 12472 KB Output is correct
23 Correct 60 ms 12472 KB Output is correct
24 Correct 60 ms 12472 KB Output is correct
25 Correct 39 ms 12472 KB Output is correct
26 Correct 46 ms 12472 KB Output is correct
27 Correct 189 ms 12524 KB Output is correct
28 Correct 113 ms 12524 KB Output is correct
29 Correct 125 ms 12524 KB Output is correct
30 Correct 138 ms 12684 KB Output is correct
31 Correct 162 ms 12684 KB Output is correct
32 Correct 159 ms 12684 KB Output is correct
33 Correct 137 ms 12716 KB Output is correct
34 Correct 109 ms 12716 KB Output is correct
35 Correct 180 ms 15056 KB Output is correct
36 Correct 145 ms 15056 KB Output is correct
37 Correct 71 ms 15056 KB Output is correct
38 Correct 71 ms 15056 KB Output is correct
39 Correct 166 ms 15276 KB Output is correct
40 Correct 191 ms 15276 KB Output is correct
41 Correct 120 ms 15276 KB Output is correct
42 Correct 174 ms 15276 KB Output is correct
43 Correct 159 ms 15276 KB Output is correct
44 Correct 167 ms 15276 KB Output is correct
45 Correct 177 ms 15276 KB Output is correct
46 Correct 93 ms 15276 KB Output is correct
47 Correct 83 ms 15276 KB Output is correct
48 Correct 90 ms 15276 KB Output is correct
49 Correct 65 ms 15276 KB Output is correct
50 Correct 60 ms 15276 KB Output is correct
51 Correct 66 ms 15276 KB Output is correct
52 Correct 69 ms 15276 KB Output is correct
53 Correct 59 ms 15276 KB Output is correct
54 Correct 61 ms 15276 KB Output is correct