Submission #827339

# Submission time Handle Problem Language Result Execution time Memory
827339 2023-08-16T11:25:10 Z beaconmc Railway (BOI17_railway) C++14
100 / 100
347 ms 45928 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
using namespace std;
//using namespace __gnu_pbds;

#define FOR(i, x, y) for(ll i=x; i<y; i++)
#define FORNEG(i, x, y) for(ll i=x; i>y; i--)
//#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)



vector<ll> edges[100001];
ll par[100001];
ll depth[100001];
ll pos[100001];
ll ancestor[100001][20];
ll timer = 1;

ll anc(ll a, ll x){
  if (depth[a] <= (1<<x)) return 1;
  if (ancestor[a][x] != -2) return ancestor[a][x];

  if (x==0) ancestor[a][x] = par[a];
  else ancestor[a][x] = anc(anc(a,x-1),x-1);

  return ancestor[a][x];
}

void dfs(ll a, ll p, ll d){
  pos[a] = timer++;
  depth[a] = d;
  par[a] = p;
  for (auto&i : edges[a]){
    if (i != p) dfs(i, a, d+1);
  }
}

ll lca(ll a, ll b){
  if (depth[b] >= depth[a]) swap(a,b);


  FORNEG(i,19,-1) if (depth[anc(a,i)] >= depth[b]) a = anc(a,i);

  if (a==b) return a;


  FORNEG(i,19,-1) if (anc(a, i) != anc(b, i)) a = anc(a,i), b = anc(b,i);

  return par[a];
}

map<pair<ll, ll>, ll> rails;

ll rail[100001];
ll vals[100001];


void calc(ll a, ll p){

  for (auto&i : edges[a]){
    if (i != p){
      calc(i, a);
      ll c,d;
      c = min(a, i);
      d = max(a, i);
      vals[rails[make_pair(c,d)]] += rail[i];
      rail[a] += rail[i];
    }
  }
}


int main(){
  FOR(i,0,100001) FOR(j,0,20) ancestor[i][j] = -2;
  FOR(i,0,100001) rail[i] = 0, vals[i] = 0;

  ll n,m,k;
  cin >> n >> m >> k;
  FOR(i,0,n-1){
    ll a,b;
    cin >> a >> b;
    edges[b].push_back(a);
    edges[a].push_back(b);
    if (a>b) swap(a,b);
    rails[make_pair(a,b)] = i+1;
  }
  dfs(1, -1, 0);

  FOR(i,0,m){
    ll a;
    cin >> a;
    vector<vector<ll>> temp;
    FOR(i,0,a){
      ll tempy; cin >> tempy;
      temp.push_back({pos[tempy], tempy});
    }
    sort(temp.begin(), temp.end());

    FOR(i,0,a-1){
      rail[temp[i][1]] += 1;
      rail[temp[i+1][1]] += 1;
      rail[(lca(temp[i][1], temp[i+1][1]))] -= 2;
    }
    rail[temp[0][1]] += 1;
    rail[temp[a-1][1]] += 1;
    rail[(lca(temp[0][1], temp[a-1][1]))] -= 2;
  }

  calc(1, -1);
  vector<ll> ans;

  FOR(i,1,n){

    if (vals[i] >= 2*k) ans.push_back(i);

  }
  cout << ans.size() << "\n";
  for (auto&i : ans) cout << i << endl;





}




# Verdict Execution time Memory Grader output
1 Correct 11 ms 19796 KB Output is correct
2 Correct 16 ms 21064 KB Output is correct
3 Correct 16 ms 21228 KB Output is correct
4 Correct 8 ms 19880 KB Output is correct
5 Correct 8 ms 19852 KB Output is correct
6 Correct 21 ms 21872 KB Output is correct
7 Correct 17 ms 21296 KB Output is correct
8 Correct 16 ms 21172 KB Output is correct
9 Correct 18 ms 21256 KB Output is correct
10 Correct 8 ms 19796 KB Output is correct
11 Correct 8 ms 19796 KB Output is correct
12 Correct 8 ms 19796 KB Output is correct
13 Correct 8 ms 19796 KB Output is correct
14 Correct 8 ms 19880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19796 KB Output is correct
2 Correct 16 ms 21064 KB Output is correct
3 Correct 16 ms 21228 KB Output is correct
4 Correct 8 ms 19880 KB Output is correct
5 Correct 8 ms 19852 KB Output is correct
6 Correct 21 ms 21872 KB Output is correct
7 Correct 17 ms 21296 KB Output is correct
8 Correct 16 ms 21172 KB Output is correct
9 Correct 18 ms 21256 KB Output is correct
10 Correct 8 ms 19796 KB Output is correct
11 Correct 8 ms 19796 KB Output is correct
12 Correct 8 ms 19796 KB Output is correct
13 Correct 8 ms 19796 KB Output is correct
14 Correct 8 ms 19880 KB Output is correct
15 Correct 53 ms 21588 KB Output is correct
16 Correct 50 ms 21552 KB Output is correct
17 Correct 53 ms 21708 KB Output is correct
18 Correct 20 ms 21736 KB Output is correct
19 Correct 17 ms 21324 KB Output is correct
20 Correct 58 ms 21760 KB Output is correct
21 Correct 54 ms 21580 KB Output is correct
22 Correct 8 ms 19796 KB Output is correct
23 Correct 16 ms 21220 KB Output is correct
24 Correct 16 ms 21132 KB Output is correct
25 Correct 8 ms 19796 KB Output is correct
26 Correct 8 ms 19796 KB Output is correct
27 Correct 21 ms 21792 KB Output is correct
28 Correct 17 ms 21332 KB Output is correct
29 Correct 15 ms 21204 KB Output is correct
30 Correct 17 ms 21192 KB Output is correct
31 Correct 9 ms 19796 KB Output is correct
32 Correct 8 ms 19808 KB Output is correct
33 Correct 8 ms 19876 KB Output is correct
34 Correct 8 ms 19836 KB Output is correct
35 Correct 8 ms 19796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 286 ms 43740 KB Output is correct
2 Correct 8 ms 19796 KB Output is correct
3 Correct 293 ms 43224 KB Output is correct
4 Correct 213 ms 42616 KB Output is correct
5 Correct 290 ms 43816 KB Output is correct
6 Correct 286 ms 43972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 37520 KB Output is correct
2 Correct 142 ms 32636 KB Output is correct
3 Correct 150 ms 32152 KB Output is correct
4 Correct 144 ms 32196 KB Output is correct
5 Correct 195 ms 32204 KB Output is correct
6 Correct 153 ms 37820 KB Output is correct
7 Correct 140 ms 37680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 37520 KB Output is correct
2 Correct 142 ms 32636 KB Output is correct
3 Correct 150 ms 32152 KB Output is correct
4 Correct 144 ms 32196 KB Output is correct
5 Correct 195 ms 32204 KB Output is correct
6 Correct 153 ms 37820 KB Output is correct
7 Correct 140 ms 37680 KB Output is correct
8 Correct 174 ms 37836 KB Output is correct
9 Correct 173 ms 39588 KB Output is correct
10 Correct 347 ms 45692 KB Output is correct
11 Correct 285 ms 45700 KB Output is correct
12 Correct 120 ms 33740 KB Output is correct
13 Correct 122 ms 33788 KB Output is correct
14 Correct 138 ms 33824 KB Output is correct
15 Correct 155 ms 33968 KB Output is correct
16 Correct 148 ms 33976 KB Output is correct
17 Correct 148 ms 33888 KB Output is correct
18 Correct 153 ms 33988 KB Output is correct
19 Correct 150 ms 34508 KB Output is correct
20 Correct 195 ms 39808 KB Output is correct
21 Correct 189 ms 39932 KB Output is correct
22 Correct 170 ms 39816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19796 KB Output is correct
2 Correct 16 ms 21064 KB Output is correct
3 Correct 16 ms 21228 KB Output is correct
4 Correct 8 ms 19880 KB Output is correct
5 Correct 8 ms 19852 KB Output is correct
6 Correct 21 ms 21872 KB Output is correct
7 Correct 17 ms 21296 KB Output is correct
8 Correct 16 ms 21172 KB Output is correct
9 Correct 18 ms 21256 KB Output is correct
10 Correct 8 ms 19796 KB Output is correct
11 Correct 8 ms 19796 KB Output is correct
12 Correct 8 ms 19796 KB Output is correct
13 Correct 8 ms 19796 KB Output is correct
14 Correct 8 ms 19880 KB Output is correct
15 Correct 53 ms 21588 KB Output is correct
16 Correct 50 ms 21552 KB Output is correct
17 Correct 53 ms 21708 KB Output is correct
18 Correct 20 ms 21736 KB Output is correct
19 Correct 17 ms 21324 KB Output is correct
20 Correct 58 ms 21760 KB Output is correct
21 Correct 54 ms 21580 KB Output is correct
22 Correct 8 ms 19796 KB Output is correct
23 Correct 16 ms 21220 KB Output is correct
24 Correct 16 ms 21132 KB Output is correct
25 Correct 8 ms 19796 KB Output is correct
26 Correct 8 ms 19796 KB Output is correct
27 Correct 21 ms 21792 KB Output is correct
28 Correct 17 ms 21332 KB Output is correct
29 Correct 15 ms 21204 KB Output is correct
30 Correct 17 ms 21192 KB Output is correct
31 Correct 9 ms 19796 KB Output is correct
32 Correct 8 ms 19808 KB Output is correct
33 Correct 8 ms 19876 KB Output is correct
34 Correct 8 ms 19836 KB Output is correct
35 Correct 8 ms 19796 KB Output is correct
36 Correct 286 ms 43740 KB Output is correct
37 Correct 8 ms 19796 KB Output is correct
38 Correct 293 ms 43224 KB Output is correct
39 Correct 213 ms 42616 KB Output is correct
40 Correct 290 ms 43816 KB Output is correct
41 Correct 286 ms 43972 KB Output is correct
42 Correct 140 ms 37520 KB Output is correct
43 Correct 142 ms 32636 KB Output is correct
44 Correct 150 ms 32152 KB Output is correct
45 Correct 144 ms 32196 KB Output is correct
46 Correct 195 ms 32204 KB Output is correct
47 Correct 153 ms 37820 KB Output is correct
48 Correct 140 ms 37680 KB Output is correct
49 Correct 174 ms 37836 KB Output is correct
50 Correct 173 ms 39588 KB Output is correct
51 Correct 347 ms 45692 KB Output is correct
52 Correct 285 ms 45700 KB Output is correct
53 Correct 120 ms 33740 KB Output is correct
54 Correct 122 ms 33788 KB Output is correct
55 Correct 138 ms 33824 KB Output is correct
56 Correct 155 ms 33968 KB Output is correct
57 Correct 148 ms 33976 KB Output is correct
58 Correct 148 ms 33888 KB Output is correct
59 Correct 153 ms 33988 KB Output is correct
60 Correct 150 ms 34508 KB Output is correct
61 Correct 195 ms 39808 KB Output is correct
62 Correct 189 ms 39932 KB Output is correct
63 Correct 170 ms 39816 KB Output is correct
64 Correct 175 ms 39704 KB Output is correct
65 Correct 160 ms 34000 KB Output is correct
66 Correct 175 ms 33844 KB Output is correct
67 Correct 177 ms 33920 KB Output is correct
68 Correct 104 ms 33728 KB Output is correct
69 Correct 111 ms 33692 KB Output is correct
70 Correct 239 ms 40128 KB Output is correct
71 Correct 188 ms 39264 KB Output is correct
72 Correct 9 ms 19796 KB Output is correct
73 Correct 16 ms 21184 KB Output is correct
74 Correct 17 ms 21180 KB Output is correct
75 Correct 9 ms 19796 KB Output is correct
76 Correct 8 ms 19876 KB Output is correct
77 Correct 23 ms 21816 KB Output is correct
78 Correct 17 ms 21332 KB Output is correct
79 Correct 15 ms 21108 KB Output is correct
80 Correct 15 ms 21172 KB Output is correct
81 Correct 8 ms 19796 KB Output is correct
82 Correct 9 ms 19828 KB Output is correct
83 Correct 8 ms 19796 KB Output is correct
84 Correct 9 ms 19876 KB Output is correct
85 Correct 8 ms 19796 KB Output is correct
86 Correct 48 ms 21496 KB Output is correct
87 Correct 51 ms 21620 KB Output is correct
88 Correct 56 ms 21708 KB Output is correct
89 Correct 20 ms 21760 KB Output is correct
90 Correct 17 ms 21300 KB Output is correct
91 Correct 54 ms 21824 KB Output is correct
92 Correct 53 ms 21648 KB Output is correct
93 Correct 9 ms 19796 KB Output is correct
94 Correct 304 ms 45596 KB Output is correct
95 Correct 292 ms 45020 KB Output is correct
96 Correct 237 ms 44328 KB Output is correct
97 Correct 301 ms 45480 KB Output is correct
98 Correct 295 ms 45928 KB Output is correct
99 Correct 157 ms 34088 KB Output is correct
100 Correct 148 ms 34000 KB Output is correct
101 Correct 155 ms 33996 KB Output is correct
102 Correct 149 ms 34464 KB Output is correct
103 Correct 143 ms 39500 KB Output is correct
104 Correct 173 ms 39908 KB Output is correct
105 Correct 166 ms 39364 KB Output is correct
106 Correct 188 ms 39820 KB Output is correct
107 Correct 174 ms 39576 KB Output is correct
108 Correct 282 ms 45680 KB Output is correct
109 Correct 324 ms 45636 KB Output is correct
110 Correct 125 ms 33752 KB Output is correct
111 Correct 121 ms 33772 KB Output is correct
112 Correct 140 ms 33908 KB Output is correct
113 Correct 165 ms 34008 KB Output is correct