Submission #775589

# Submission time Handle Problem Language Result Execution time Memory
775589 2023-07-06T14:42:41 Z hgmhc None (JOI16_ho_t3) C++17
100 / 100
89 ms 18508 KB
#include <bits/stdc++.h>
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
#define per(i,a,b) for (auto i = (b); i >= (a); --i)
#define all(x) begin(x),end(x)
#define siz(x) int((x).size())
#define Mup(x,y) x = max(x,y)
#define mup(x,y) x = min(x,y)
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define fi first
#define se second
using namespace std; using ll = long long; using ii = pair<int,int>;

const int N = 1e5+3, M = 2e5+3, Q = M;
int n, m, q;
ii edge[M];
vector<ii> adj[N];
int r[Q], ans[Q];
int dist[N], deltime[M];
int ind[N];

void bfs_to_make_DAG() {
    bool vis[N]{};
    queue<int> q;
    q.push(1), dist[1] = 0, vis[1] = true;
    while (not empty(q)) {
        int s = q.front(); q.pop();
        for (auto [i,u] : adj[s]) {
            if (vis[u]) continue;
            vis[u] = true;
            dist[u]=dist[s]+1;
            q.push(u);
        }
    }
}

void topology_dp() {
    queue<int> q;
    q.push(1), deltime[1] = ::q+1;
    while (not empty(q)) {
        int s = q.front(); q.pop();
        for (auto [u,w] : adj[s]) {
            Mup(deltime[u], min(deltime[s],w));
            if (--ind[u] == 0) q.push(u);
        }
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m >> q;
    rep(i,1,m) {
        cin >> edge[i].fi >> edge[i].se;
        adj[edge[i].fi].push_back({i,edge[i].se});
        adj[edge[i].se].push_back({i,edge[i].fi});
    }
    bfs_to_make_DAG();
    fill(deltime,deltime+M,1e9);
    rep(i,1,q) {
        cin >> r[i];
        deltime[r[i]] = i;
    }
    rep(i,1,n) adj[i].clear();
    
    rep(i,1,m) {
        auto &[u,v] = edge[i];
        if (dist[u]>dist[v]) swap(u,v);
        if (dist[v]-dist[u]==1) {
            adj[u].push_back({v,deltime[i]});
            ind[v]++;
        }
    }
    fill(deltime,deltime+M,-1);
    topology_dp();
    rep(i,1,n) ans[deltime[i]]++;
    rep(i,1,q) cout << (ans[i]+=ans[i-1]) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3540 KB Output is correct
2 Correct 2 ms 3576 KB Output is correct
3 Correct 3 ms 3708 KB Output is correct
4 Correct 2 ms 3540 KB Output is correct
5 Correct 2 ms 3540 KB Output is correct
6 Correct 2 ms 3580 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3540 KB Output is correct
2 Correct 2 ms 3576 KB Output is correct
3 Correct 3 ms 3708 KB Output is correct
4 Correct 2 ms 3540 KB Output is correct
5 Correct 2 ms 3540 KB Output is correct
6 Correct 2 ms 3580 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
9 Correct 77 ms 14604 KB Output is correct
10 Correct 59 ms 14476 KB Output is correct
11 Correct 56 ms 14096 KB Output is correct
12 Correct 57 ms 14244 KB Output is correct
13 Correct 56 ms 14380 KB Output is correct
14 Correct 61 ms 14284 KB Output is correct
15 Correct 35 ms 10444 KB Output is correct
16 Correct 37 ms 9412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 12280 KB Output is correct
2 Correct 61 ms 14528 KB Output is correct
3 Correct 44 ms 12440 KB Output is correct
4 Correct 58 ms 14200 KB Output is correct
5 Correct 54 ms 14212 KB Output is correct
6 Correct 57 ms 14268 KB Output is correct
7 Correct 29 ms 9392 KB Output is correct
8 Correct 36 ms 9292 KB Output is correct
9 Correct 24 ms 9120 KB Output is correct
10 Correct 19 ms 9212 KB Output is correct
11 Correct 62 ms 14852 KB Output is correct
12 Correct 59 ms 14248 KB Output is correct
13 Correct 59 ms 14088 KB Output is correct
14 Correct 66 ms 14844 KB Output is correct
15 Correct 68 ms 14548 KB Output is correct
16 Correct 78 ms 14192 KB Output is correct
17 Correct 72 ms 15132 KB Output is correct
18 Correct 43 ms 11264 KB Output is correct
19 Correct 84 ms 18204 KB Output is correct
20 Correct 87 ms 15200 KB Output is correct
21 Correct 34 ms 10316 KB Output is correct
22 Correct 34 ms 10240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3540 KB Output is correct
2 Correct 2 ms 3576 KB Output is correct
3 Correct 3 ms 3708 KB Output is correct
4 Correct 2 ms 3540 KB Output is correct
5 Correct 2 ms 3540 KB Output is correct
6 Correct 2 ms 3580 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
9 Correct 77 ms 14604 KB Output is correct
10 Correct 59 ms 14476 KB Output is correct
11 Correct 56 ms 14096 KB Output is correct
12 Correct 57 ms 14244 KB Output is correct
13 Correct 56 ms 14380 KB Output is correct
14 Correct 61 ms 14284 KB Output is correct
15 Correct 35 ms 10444 KB Output is correct
16 Correct 37 ms 9412 KB Output is correct
17 Correct 60 ms 12280 KB Output is correct
18 Correct 61 ms 14528 KB Output is correct
19 Correct 44 ms 12440 KB Output is correct
20 Correct 58 ms 14200 KB Output is correct
21 Correct 54 ms 14212 KB Output is correct
22 Correct 57 ms 14268 KB Output is correct
23 Correct 29 ms 9392 KB Output is correct
24 Correct 36 ms 9292 KB Output is correct
25 Correct 24 ms 9120 KB Output is correct
26 Correct 19 ms 9212 KB Output is correct
27 Correct 62 ms 14852 KB Output is correct
28 Correct 59 ms 14248 KB Output is correct
29 Correct 59 ms 14088 KB Output is correct
30 Correct 66 ms 14844 KB Output is correct
31 Correct 68 ms 14548 KB Output is correct
32 Correct 78 ms 14192 KB Output is correct
33 Correct 72 ms 15132 KB Output is correct
34 Correct 43 ms 11264 KB Output is correct
35 Correct 84 ms 18204 KB Output is correct
36 Correct 87 ms 15200 KB Output is correct
37 Correct 34 ms 10316 KB Output is correct
38 Correct 34 ms 10240 KB Output is correct
39 Correct 83 ms 18500 KB Output is correct
40 Correct 86 ms 18508 KB Output is correct
41 Correct 52 ms 14496 KB Output is correct
42 Correct 79 ms 18124 KB Output is correct
43 Correct 81 ms 18236 KB Output is correct
44 Correct 89 ms 18216 KB Output is correct
45 Correct 79 ms 18116 KB Output is correct
46 Correct 48 ms 11980 KB Output is correct
47 Correct 39 ms 11412 KB Output is correct
48 Correct 38 ms 11232 KB Output is correct
49 Correct 31 ms 10752 KB Output is correct
50 Correct 28 ms 10824 KB Output is correct
51 Correct 32 ms 11332 KB Output is correct
52 Correct 30 ms 11496 KB Output is correct
53 Correct 28 ms 10688 KB Output is correct
54 Correct 27 ms 10896 KB Output is correct