Submission #1085030

# Submission time Handle Problem Language Result Execution time Memory
1085030 2024-09-07T10:40:23 Z TheGreatAntivirus Railway (BOI17_railway) C++17
100 / 100
77 ms 44740 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define stdI freopen("input.txt", "r", stdin);
#define stdO freopen("output.txt", "w", stdout);
#define all(x) x.begin(), x.end()
#define mp(x, y) make_pair(x, y)
#define int long long
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef tree<int,
    null_type,less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update> ordered_set;

typedef pair<int, int> pii;

const int MAXN = 2e5 + 100, MAXLOG = 20, INF = 1e18, MOD = 1e9 + 7;

struct ad
{
    int u, i;
};

vector<ad> adj[MAXN];
vector<int> ans;
int st[MAXN], h[MAXN], par[MAXN][MAXLOG], cnt[MAXN];
int n, m, k, t;

bool cmp(int a, int b)
{
    return st[a] < st[b];
}

void predfs(int v, int p)
{
    par[v][0] = p;
    st[v] = ++t;
    for(int i = 1; i < MAXLOG; i++)
    {
        par[v][i] = par[par[v][i - 1]][i - 1];
    }
    for(auto u : adj[v])
    {
        if(u.u != p)
        {
            h[u.u] = h[v] + 1;
            predfs(u.u, v);
        }
    }
    t++;
}

int lca(int u, int v)
{
    if(h[u] < h[v])
    {
        swap(u, v);
    }
    for(int i = MAXLOG - 1; i > -1; i--)
    {
        if(h[par[u][i]] >= h[v])
        {
            u = par[u][i];
        }
    }
    if(u == v)
    {
        return v;
    }
    for(int i = MAXLOG - 1; i > -1; i--)
    {
        if(par[u][i] != par[v][i])
        {
            u = par[u][i]; v = par[v][i];
        }
    }
    return par[u][0];
}

void dfs(int v, int p, int ip)
{
    for(auto u : adj[v])
    {
        if(u.u != p)
        {
            dfs(u.u, v, u.i);
            cnt[v] += cnt[u.u];
        }
    }
    if(cnt[v] >= 2 * k && v != 1)
    {
        ans.push_back(ip);
    }
}

void solve()
{
    cin >> n >> m >> k; h[0] = -INF;
    for(int i = 1; i < n; i++)
    {
        int u, v; cin >> u >> v;
        adj[u].push_back({v, i}); adj[v].push_back({u, i});
    }
    predfs(1, 0);
    for(int i = 0; i < m; i++)
    {
        int w; cin >> w;
        int t[w];
        for(int j = 0; j < w; j++)
        {
            cin >> t[j];
        }
        sort(t, t + w, cmp);
        for(int j = 1; j < w; j++)
        {
            cnt[t[j]]++; cnt[t[j - 1]]++;
            cnt[lca(t[j], t[j - 1])] -= 2;
        }
        cnt[t[0]]++; cnt[t[w - 1]]++;
        cnt[lca(t[0], t[w - 1])] -= 2;
    }
    dfs(1, 0, 0);
    cout << ans.size() << "\n";
    sort(all(ans));
    for(auto x : ans)
    {
        cout << x << " ";
    }
    cout << "\n";
}

int32_t main()
{
    IOS;
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12120 KB Output is correct
2 Correct 6 ms 14940 KB Output is correct
3 Correct 7 ms 14844 KB Output is correct
4 Correct 2 ms 12124 KB Output is correct
5 Correct 2 ms 12108 KB Output is correct
6 Correct 6 ms 15452 KB Output is correct
7 Correct 5 ms 15044 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 14940 KB Output is correct
10 Correct 2 ms 12124 KB Output is correct
11 Correct 2 ms 12124 KB Output is correct
12 Correct 2 ms 12124 KB Output is correct
13 Correct 2 ms 12124 KB Output is correct
14 Correct 2 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12120 KB Output is correct
2 Correct 6 ms 14940 KB Output is correct
3 Correct 7 ms 14844 KB Output is correct
4 Correct 2 ms 12124 KB Output is correct
5 Correct 2 ms 12108 KB Output is correct
6 Correct 6 ms 15452 KB Output is correct
7 Correct 5 ms 15044 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 14940 KB Output is correct
10 Correct 2 ms 12124 KB Output is correct
11 Correct 2 ms 12124 KB Output is correct
12 Correct 2 ms 12124 KB Output is correct
13 Correct 2 ms 12124 KB Output is correct
14 Correct 2 ms 12124 KB Output is correct
15 Correct 20 ms 15192 KB Output is correct
16 Correct 22 ms 15296 KB Output is correct
17 Correct 23 ms 15444 KB Output is correct
18 Correct 6 ms 15448 KB Output is correct
19 Correct 6 ms 14940 KB Output is correct
20 Correct 28 ms 15448 KB Output is correct
21 Correct 31 ms 15448 KB Output is correct
22 Correct 2 ms 12124 KB Output is correct
23 Correct 5 ms 14784 KB Output is correct
24 Correct 5 ms 14940 KB Output is correct
25 Correct 2 ms 12124 KB Output is correct
26 Correct 2 ms 12124 KB Output is correct
27 Correct 6 ms 15452 KB Output is correct
28 Correct 6 ms 14948 KB Output is correct
29 Correct 5 ms 14940 KB Output is correct
30 Correct 5 ms 14892 KB Output is correct
31 Correct 2 ms 12124 KB Output is correct
32 Correct 2 ms 12124 KB Output is correct
33 Correct 2 ms 12124 KB Output is correct
34 Correct 2 ms 12124 KB Output is correct
35 Correct 2 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 42444 KB Output is correct
2 Correct 2 ms 12120 KB Output is correct
3 Correct 65 ms 43920 KB Output is correct
4 Correct 58 ms 43092 KB Output is correct
5 Correct 62 ms 44324 KB Output is correct
6 Correct 67 ms 44740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 37712 KB Output is correct
2 Correct 53 ms 36180 KB Output is correct
3 Correct 55 ms 35664 KB Output is correct
4 Correct 59 ms 35772 KB Output is correct
5 Correct 58 ms 35664 KB Output is correct
6 Correct 59 ms 39796 KB Output is correct
7 Correct 51 ms 39684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 37712 KB Output is correct
2 Correct 53 ms 36180 KB Output is correct
3 Correct 55 ms 35664 KB Output is correct
4 Correct 59 ms 35772 KB Output is correct
5 Correct 58 ms 35664 KB Output is correct
6 Correct 59 ms 39796 KB Output is correct
7 Correct 51 ms 39684 KB Output is correct
8 Correct 58 ms 39852 KB Output is correct
9 Correct 61 ms 39764 KB Output is correct
10 Correct 57 ms 44484 KB Output is correct
11 Correct 59 ms 44484 KB Output is correct
12 Correct 49 ms 35008 KB Output is correct
13 Correct 46 ms 35028 KB Output is correct
14 Correct 63 ms 35568 KB Output is correct
15 Correct 57 ms 35668 KB Output is correct
16 Correct 59 ms 35780 KB Output is correct
17 Correct 55 ms 35664 KB Output is correct
18 Correct 54 ms 35756 KB Output is correct
19 Correct 53 ms 35984 KB Output is correct
20 Correct 52 ms 39936 KB Output is correct
21 Correct 51 ms 40260 KB Output is correct
22 Correct 62 ms 40144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12120 KB Output is correct
2 Correct 6 ms 14940 KB Output is correct
3 Correct 7 ms 14844 KB Output is correct
4 Correct 2 ms 12124 KB Output is correct
5 Correct 2 ms 12108 KB Output is correct
6 Correct 6 ms 15452 KB Output is correct
7 Correct 5 ms 15044 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 14940 KB Output is correct
10 Correct 2 ms 12124 KB Output is correct
11 Correct 2 ms 12124 KB Output is correct
12 Correct 2 ms 12124 KB Output is correct
13 Correct 2 ms 12124 KB Output is correct
14 Correct 2 ms 12124 KB Output is correct
15 Correct 20 ms 15192 KB Output is correct
16 Correct 22 ms 15296 KB Output is correct
17 Correct 23 ms 15444 KB Output is correct
18 Correct 6 ms 15448 KB Output is correct
19 Correct 6 ms 14940 KB Output is correct
20 Correct 28 ms 15448 KB Output is correct
21 Correct 31 ms 15448 KB Output is correct
22 Correct 2 ms 12124 KB Output is correct
23 Correct 5 ms 14784 KB Output is correct
24 Correct 5 ms 14940 KB Output is correct
25 Correct 2 ms 12124 KB Output is correct
26 Correct 2 ms 12124 KB Output is correct
27 Correct 6 ms 15452 KB Output is correct
28 Correct 6 ms 14948 KB Output is correct
29 Correct 5 ms 14940 KB Output is correct
30 Correct 5 ms 14892 KB Output is correct
31 Correct 2 ms 12124 KB Output is correct
32 Correct 2 ms 12124 KB Output is correct
33 Correct 2 ms 12124 KB Output is correct
34 Correct 2 ms 12124 KB Output is correct
35 Correct 2 ms 12124 KB Output is correct
36 Correct 72 ms 42444 KB Output is correct
37 Correct 2 ms 12120 KB Output is correct
38 Correct 65 ms 43920 KB Output is correct
39 Correct 58 ms 43092 KB Output is correct
40 Correct 62 ms 44324 KB Output is correct
41 Correct 67 ms 44740 KB Output is correct
42 Correct 51 ms 37712 KB Output is correct
43 Correct 53 ms 36180 KB Output is correct
44 Correct 55 ms 35664 KB Output is correct
45 Correct 59 ms 35772 KB Output is correct
46 Correct 58 ms 35664 KB Output is correct
47 Correct 59 ms 39796 KB Output is correct
48 Correct 51 ms 39684 KB Output is correct
49 Correct 58 ms 39852 KB Output is correct
50 Correct 61 ms 39764 KB Output is correct
51 Correct 57 ms 44484 KB Output is correct
52 Correct 59 ms 44484 KB Output is correct
53 Correct 49 ms 35008 KB Output is correct
54 Correct 46 ms 35028 KB Output is correct
55 Correct 63 ms 35568 KB Output is correct
56 Correct 57 ms 35668 KB Output is correct
57 Correct 59 ms 35780 KB Output is correct
58 Correct 55 ms 35664 KB Output is correct
59 Correct 54 ms 35756 KB Output is correct
60 Correct 53 ms 35984 KB Output is correct
61 Correct 52 ms 39936 KB Output is correct
62 Correct 51 ms 40260 KB Output is correct
63 Correct 62 ms 40144 KB Output is correct
64 Correct 56 ms 40020 KB Output is correct
65 Correct 60 ms 35664 KB Output is correct
66 Correct 64 ms 35668 KB Output is correct
67 Correct 59 ms 35668 KB Output is correct
68 Correct 37 ms 34856 KB Output is correct
69 Correct 45 ms 34648 KB Output is correct
70 Correct 59 ms 40392 KB Output is correct
71 Correct 61 ms 39508 KB Output is correct
72 Correct 2 ms 12124 KB Output is correct
73 Correct 5 ms 14940 KB Output is correct
74 Correct 5 ms 14940 KB Output is correct
75 Correct 2 ms 12268 KB Output is correct
76 Correct 2 ms 12268 KB Output is correct
77 Correct 5 ms 15452 KB Output is correct
78 Correct 5 ms 15192 KB Output is correct
79 Correct 5 ms 14976 KB Output is correct
80 Correct 4 ms 14940 KB Output is correct
81 Correct 2 ms 12124 KB Output is correct
82 Correct 2 ms 12120 KB Output is correct
83 Correct 2 ms 12124 KB Output is correct
84 Correct 2 ms 12124 KB Output is correct
85 Correct 2 ms 12124 KB Output is correct
86 Correct 22 ms 15376 KB Output is correct
87 Correct 21 ms 15452 KB Output is correct
88 Correct 22 ms 15444 KB Output is correct
89 Correct 5 ms 15452 KB Output is correct
90 Correct 5 ms 14940 KB Output is correct
91 Correct 25 ms 15568 KB Output is correct
92 Correct 28 ms 15196 KB Output is correct
93 Correct 3 ms 12124 KB Output is correct
94 Correct 77 ms 44236 KB Output is correct
95 Correct 69 ms 43860 KB Output is correct
96 Correct 57 ms 43092 KB Output is correct
97 Correct 64 ms 44232 KB Output is correct
98 Correct 66 ms 44740 KB Output is correct
99 Correct 56 ms 35676 KB Output is correct
100 Correct 56 ms 35664 KB Output is correct
101 Correct 56 ms 35668 KB Output is correct
102 Correct 60 ms 36184 KB Output is correct
103 Correct 60 ms 39760 KB Output is correct
104 Correct 60 ms 40100 KB Output is correct
105 Correct 52 ms 39616 KB Output is correct
106 Correct 65 ms 39888 KB Output is correct
107 Correct 60 ms 39760 KB Output is correct
108 Correct 60 ms 44488 KB Output is correct
109 Correct 60 ms 44484 KB Output is correct
110 Correct 47 ms 34776 KB Output is correct
111 Correct 47 ms 34792 KB Output is correct
112 Correct 54 ms 35664 KB Output is correct
113 Correct 54 ms 35636 KB Output is correct