Submission #960853

# Submission time Handle Problem Language Result Execution time Memory
960853 2024-04-11T06:31:44 Z Trisanu_Das Jail (JOI22_jail) C++17
100 / 100
1171 ms 308284 KB
#include<bits/stdc++.h>
using namespace std;
 
const int N=1.2e5,H=17,N_=N+2*N*H;
 
vector<int>g[N],q[N_];
int p[H][N],d[N],w[N_];
 
inline int z(int i,int h,int t){
 return (i*H+h)*2+t;
}
 
void dfs(int i){
 for(int h=0;h<H-1;h++){
  p[h+1][i]=p[h][p[h][i]];
  q[z(i,h,0)].push_back(z(i,h+1,0));
  q[z(p[h][i],h,0)].push_back(z(i,h+1,0));
  q[z(i,h+1,1)].push_back(z(i,h,1));
  q[z(i,h+1,1)].push_back(z(p[h][i],h,1));
 }
 for(int j:g[i])
  if(p[0][i]!=j){
   p[0][j]=i;
   d[j]=d[i]+1;
   dfs(j);
  }
}
 
int lca(int i,int j){
 if(d[i]<d[j])
  swap(i,j);
 int k=d[i]-d[j];
 for(int h=0;h<H;h++)
  if(k>>h&1)
   i=p[h][i];
 if(i==j)
  return i;
 for(int h=H-1;h>=0;h--)
  if(p[h][i]!=p[h][j])
   i=p[h][i],j=p[h][j];
 return p[0][i];
}
 
 
template<class F>
void up(int i,int k,const F&f) {
 if(k<0)
  return;
 for(int h=0;h<H;h++)
  if(k>>h&1)
   f(i,h),i=p[h][i];
 f(i,0);
}
 
int main() {
 ios::sync_with_stdio(0),cin.tie(0);
 int t;
 cin>>t;
 while(t--){
  int n;
  cin>>n;
  for(int h=0;h<n-1;h++){
   int i,j;
   cin>>i>>j,i--,j--;
   g[i].push_back(j),g[j].push_back(i);
  }
  dfs(0);
  int m;
  cin>>m;
  for(int h=0;h<m;h++){
   int i,j;
   cin>>i>>j,i--,j--;
   q[n*H*2+h].push_back(z(i,0,0));
   q[z(j,0,1)].push_back(n*H*2+h);
   int f=lca(i,j);
   if(i!=f){
    up(p[0][i],d[i]-d[f]-1,[&](int u,int v){
     q[z(u,v,0)].push_back(n*H*2+h);
    });
    up(j,d[j]-d[f]-1,[&](int u,int v){
     q[z(u,v,0)].push_back(n*H*2+h);
    });
   }else
    up(j,d[j]-d[f]-1,[&](int u,int v){
     q[z(u,v,0)].push_back(n*H*2+h);
    });
   if(j!=f){
    up(p[0][j],d[j]-d[f]-1,[&](int u,int v){
     q[n*H*2+h].push_back(z(u,v,1));
    });
    up(i,d[i]-d[f]-1,[&](int u,int v){
     q[n*H*2+h].push_back(z(u,v,1));
    });
   }else
    up(i,d[i]-d[f]-1,[&](int u,int v){
     q[n*H*2+h].push_back(z(u,v,1));
    });
  }
  for(int i = 0; i < n * H * 2 + m; i++)
   for(int j : q[i]) w[j]++;
  vector<int> o;
  for(int i=0;i<n*H*2+m;i++) if(!w[i]) o.push_back(i);
  for(int u = 0; u < o.size(); u++){
   int i = o[u];
   for(int j:q[i]) if(--w[j] == 0) o.push_back(j);
  }
  cout << ((int)o.size() == n * H * 2 + m? "Yes\n" : "No\n");
  for(int i = 0; i < n; i++) g[i].clear();
  for(int i = 0; i < n * H * 2 + m; i++) q[i].clear(), w[i] = 0;
 }
}

Compilation message

jail.cpp: In function 'int main()':
jail.cpp:103:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |   for(int u = 0; u < o.size(); u++){
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 57 ms 108116 KB Output is correct
2 Correct 25 ms 108124 KB Output is correct
3 Correct 27 ms 108124 KB Output is correct
4 Correct 54 ms 108868 KB Output is correct
5 Correct 84 ms 109108 KB Output is correct
6 Correct 28 ms 108624 KB Output is correct
7 Correct 28 ms 108636 KB Output is correct
8 Correct 29 ms 108684 KB Output is correct
9 Correct 187 ms 120552 KB Output is correct
10 Correct 996 ms 282580 KB Output is correct
11 Correct 37 ms 108328 KB Output is correct
12 Correct 96 ms 109264 KB Output is correct
13 Correct 1006 ms 287324 KB Output is correct
14 Correct 891 ms 279220 KB Output is correct
15 Correct 908 ms 273756 KB Output is correct
16 Correct 1091 ms 281544 KB Output is correct
17 Correct 1073 ms 290716 KB Output is correct
18 Correct 1058 ms 308284 KB Output is correct
19 Correct 1047 ms 290016 KB Output is correct
20 Correct 971 ms 290624 KB Output is correct
21 Correct 864 ms 275080 KB Output is correct
22 Correct 880 ms 278964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 108120 KB Output is correct
2 Correct 25 ms 107988 KB Output is correct
3 Correct 30 ms 108548 KB Output is correct
4 Correct 28 ms 108636 KB Output is correct
5 Correct 32 ms 108628 KB Output is correct
6 Correct 29 ms 108636 KB Output is correct
7 Correct 31 ms 108652 KB Output is correct
8 Correct 28 ms 108488 KB Output is correct
9 Correct 31 ms 108496 KB Output is correct
10 Correct 30 ms 108636 KB Output is correct
11 Correct 29 ms 108644 KB Output is correct
12 Correct 27 ms 108380 KB Output is correct
13 Correct 26 ms 108376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 108120 KB Output is correct
2 Correct 25 ms 107988 KB Output is correct
3 Correct 30 ms 108548 KB Output is correct
4 Correct 28 ms 108636 KB Output is correct
5 Correct 32 ms 108628 KB Output is correct
6 Correct 29 ms 108636 KB Output is correct
7 Correct 31 ms 108652 KB Output is correct
8 Correct 28 ms 108488 KB Output is correct
9 Correct 31 ms 108496 KB Output is correct
10 Correct 30 ms 108636 KB Output is correct
11 Correct 29 ms 108644 KB Output is correct
12 Correct 27 ms 108380 KB Output is correct
13 Correct 26 ms 108376 KB Output is correct
14 Correct 24 ms 108124 KB Output is correct
15 Correct 25 ms 108124 KB Output is correct
16 Correct 30 ms 108604 KB Output is correct
17 Correct 29 ms 108632 KB Output is correct
18 Correct 29 ms 108888 KB Output is correct
19 Correct 28 ms 108124 KB Output is correct
20 Correct 30 ms 108636 KB Output is correct
21 Correct 30 ms 108680 KB Output is correct
22 Correct 30 ms 108652 KB Output is correct
23 Correct 25 ms 108120 KB Output is correct
24 Correct 25 ms 108376 KB Output is correct
25 Correct 29 ms 108628 KB Output is correct
26 Correct 26 ms 108376 KB Output is correct
27 Correct 28 ms 108640 KB Output is correct
28 Correct 26 ms 108060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 108120 KB Output is correct
2 Correct 25 ms 107988 KB Output is correct
3 Correct 30 ms 108548 KB Output is correct
4 Correct 28 ms 108636 KB Output is correct
5 Correct 32 ms 108628 KB Output is correct
6 Correct 29 ms 108636 KB Output is correct
7 Correct 31 ms 108652 KB Output is correct
8 Correct 28 ms 108488 KB Output is correct
9 Correct 31 ms 108496 KB Output is correct
10 Correct 30 ms 108636 KB Output is correct
11 Correct 29 ms 108644 KB Output is correct
12 Correct 27 ms 108380 KB Output is correct
13 Correct 26 ms 108376 KB Output is correct
14 Correct 24 ms 108124 KB Output is correct
15 Correct 25 ms 108124 KB Output is correct
16 Correct 30 ms 108604 KB Output is correct
17 Correct 29 ms 108632 KB Output is correct
18 Correct 29 ms 108888 KB Output is correct
19 Correct 28 ms 108124 KB Output is correct
20 Correct 30 ms 108636 KB Output is correct
21 Correct 30 ms 108680 KB Output is correct
22 Correct 30 ms 108652 KB Output is correct
23 Correct 25 ms 108120 KB Output is correct
24 Correct 25 ms 108376 KB Output is correct
25 Correct 29 ms 108628 KB Output is correct
26 Correct 26 ms 108376 KB Output is correct
27 Correct 28 ms 108640 KB Output is correct
28 Correct 26 ms 108060 KB Output is correct
29 Correct 30 ms 108884 KB Output is correct
30 Correct 29 ms 108636 KB Output is correct
31 Correct 30 ms 108800 KB Output is correct
32 Correct 30 ms 108672 KB Output is correct
33 Correct 29 ms 108636 KB Output is correct
34 Correct 29 ms 108552 KB Output is correct
35 Correct 28 ms 108380 KB Output is correct
36 Correct 28 ms 108380 KB Output is correct
37 Correct 30 ms 108380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 108120 KB Output is correct
2 Correct 25 ms 107988 KB Output is correct
3 Correct 30 ms 108548 KB Output is correct
4 Correct 28 ms 108636 KB Output is correct
5 Correct 32 ms 108628 KB Output is correct
6 Correct 29 ms 108636 KB Output is correct
7 Correct 31 ms 108652 KB Output is correct
8 Correct 28 ms 108488 KB Output is correct
9 Correct 31 ms 108496 KB Output is correct
10 Correct 30 ms 108636 KB Output is correct
11 Correct 29 ms 108644 KB Output is correct
12 Correct 27 ms 108380 KB Output is correct
13 Correct 26 ms 108376 KB Output is correct
14 Correct 24 ms 108124 KB Output is correct
15 Correct 25 ms 108124 KB Output is correct
16 Correct 30 ms 108604 KB Output is correct
17 Correct 29 ms 108632 KB Output is correct
18 Correct 29 ms 108888 KB Output is correct
19 Correct 28 ms 108124 KB Output is correct
20 Correct 30 ms 108636 KB Output is correct
21 Correct 30 ms 108680 KB Output is correct
22 Correct 30 ms 108652 KB Output is correct
23 Correct 25 ms 108120 KB Output is correct
24 Correct 25 ms 108376 KB Output is correct
25 Correct 29 ms 108628 KB Output is correct
26 Correct 26 ms 108376 KB Output is correct
27 Correct 28 ms 108640 KB Output is correct
28 Correct 26 ms 108060 KB Output is correct
29 Correct 30 ms 108884 KB Output is correct
30 Correct 29 ms 108636 KB Output is correct
31 Correct 30 ms 108800 KB Output is correct
32 Correct 30 ms 108672 KB Output is correct
33 Correct 29 ms 108636 KB Output is correct
34 Correct 29 ms 108552 KB Output is correct
35 Correct 28 ms 108380 KB Output is correct
36 Correct 28 ms 108380 KB Output is correct
37 Correct 30 ms 108380 KB Output is correct
38 Correct 213 ms 120572 KB Output is correct
39 Correct 969 ms 283448 KB Output is correct
40 Correct 214 ms 121128 KB Output is correct
41 Correct 275 ms 120664 KB Output is correct
42 Correct 209 ms 121512 KB Output is correct
43 Correct 253 ms 121476 KB Output is correct
44 Correct 45 ms 110436 KB Output is correct
45 Correct 848 ms 275448 KB Output is correct
46 Correct 838 ms 275872 KB Output is correct
47 Correct 959 ms 276564 KB Output is correct
48 Correct 946 ms 276452 KB Output is correct
49 Correct 697 ms 276820 KB Output is correct
50 Correct 738 ms 277360 KB Output is correct
51 Correct 820 ms 276988 KB Output is correct
52 Correct 796 ms 277332 KB Output is correct
53 Correct 86 ms 123084 KB Output is correct
54 Correct 1032 ms 275996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 108144 KB Output is correct
2 Correct 27 ms 108192 KB Output is correct
3 Correct 26 ms 108072 KB Output is correct
4 Correct 25 ms 108196 KB Output is correct
5 Correct 40 ms 108124 KB Output is correct
6 Correct 27 ms 108380 KB Output is correct
7 Correct 27 ms 108376 KB Output is correct
8 Correct 24 ms 108120 KB Output is correct
9 Correct 26 ms 108208 KB Output is correct
10 Correct 27 ms 108376 KB Output is correct
11 Correct 25 ms 108148 KB Output is correct
12 Correct 29 ms 108576 KB Output is correct
13 Correct 68 ms 108888 KB Output is correct
14 Correct 107 ms 109280 KB Output is correct
15 Correct 83 ms 108884 KB Output is correct
16 Correct 1055 ms 277864 KB Output is correct
17 Correct 912 ms 275632 KB Output is correct
18 Correct 1002 ms 283468 KB Output is correct
19 Correct 972 ms 278204 KB Output is correct
20 Correct 984 ms 278944 KB Output is correct
21 Correct 985 ms 279196 KB Output is correct
22 Correct 838 ms 284344 KB Output is correct
23 Correct 777 ms 275340 KB Output is correct
24 Correct 955 ms 284648 KB Output is correct
25 Correct 926 ms 283352 KB Output is correct
26 Correct 934 ms 284072 KB Output is correct
27 Correct 1086 ms 304116 KB Output is correct
28 Correct 837 ms 278652 KB Output is correct
29 Correct 887 ms 279868 KB Output is correct
30 Correct 1012 ms 281808 KB Output is correct
31 Correct 937 ms 282248 KB Output is correct
32 Correct 997 ms 282960 KB Output is correct
33 Correct 787 ms 273624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 108116 KB Output is correct
2 Correct 25 ms 108124 KB Output is correct
3 Correct 27 ms 108124 KB Output is correct
4 Correct 54 ms 108868 KB Output is correct
5 Correct 84 ms 109108 KB Output is correct
6 Correct 28 ms 108624 KB Output is correct
7 Correct 28 ms 108636 KB Output is correct
8 Correct 29 ms 108684 KB Output is correct
9 Correct 187 ms 120552 KB Output is correct
10 Correct 996 ms 282580 KB Output is correct
11 Correct 37 ms 108328 KB Output is correct
12 Correct 96 ms 109264 KB Output is correct
13 Correct 1006 ms 287324 KB Output is correct
14 Correct 891 ms 279220 KB Output is correct
15 Correct 908 ms 273756 KB Output is correct
16 Correct 1091 ms 281544 KB Output is correct
17 Correct 1073 ms 290716 KB Output is correct
18 Correct 1058 ms 308284 KB Output is correct
19 Correct 1047 ms 290016 KB Output is correct
20 Correct 971 ms 290624 KB Output is correct
21 Correct 864 ms 275080 KB Output is correct
22 Correct 880 ms 278964 KB Output is correct
23 Correct 26 ms 108120 KB Output is correct
24 Correct 25 ms 107988 KB Output is correct
25 Correct 30 ms 108548 KB Output is correct
26 Correct 28 ms 108636 KB Output is correct
27 Correct 32 ms 108628 KB Output is correct
28 Correct 29 ms 108636 KB Output is correct
29 Correct 31 ms 108652 KB Output is correct
30 Correct 28 ms 108488 KB Output is correct
31 Correct 31 ms 108496 KB Output is correct
32 Correct 30 ms 108636 KB Output is correct
33 Correct 29 ms 108644 KB Output is correct
34 Correct 27 ms 108380 KB Output is correct
35 Correct 26 ms 108376 KB Output is correct
36 Correct 24 ms 108124 KB Output is correct
37 Correct 25 ms 108124 KB Output is correct
38 Correct 30 ms 108604 KB Output is correct
39 Correct 29 ms 108632 KB Output is correct
40 Correct 29 ms 108888 KB Output is correct
41 Correct 28 ms 108124 KB Output is correct
42 Correct 30 ms 108636 KB Output is correct
43 Correct 30 ms 108680 KB Output is correct
44 Correct 30 ms 108652 KB Output is correct
45 Correct 25 ms 108120 KB Output is correct
46 Correct 25 ms 108376 KB Output is correct
47 Correct 29 ms 108628 KB Output is correct
48 Correct 26 ms 108376 KB Output is correct
49 Correct 28 ms 108640 KB Output is correct
50 Correct 26 ms 108060 KB Output is correct
51 Correct 30 ms 108884 KB Output is correct
52 Correct 29 ms 108636 KB Output is correct
53 Correct 30 ms 108800 KB Output is correct
54 Correct 30 ms 108672 KB Output is correct
55 Correct 29 ms 108636 KB Output is correct
56 Correct 29 ms 108552 KB Output is correct
57 Correct 28 ms 108380 KB Output is correct
58 Correct 28 ms 108380 KB Output is correct
59 Correct 30 ms 108380 KB Output is correct
60 Correct 213 ms 120572 KB Output is correct
61 Correct 969 ms 283448 KB Output is correct
62 Correct 214 ms 121128 KB Output is correct
63 Correct 275 ms 120664 KB Output is correct
64 Correct 209 ms 121512 KB Output is correct
65 Correct 253 ms 121476 KB Output is correct
66 Correct 45 ms 110436 KB Output is correct
67 Correct 848 ms 275448 KB Output is correct
68 Correct 838 ms 275872 KB Output is correct
69 Correct 959 ms 276564 KB Output is correct
70 Correct 946 ms 276452 KB Output is correct
71 Correct 697 ms 276820 KB Output is correct
72 Correct 738 ms 277360 KB Output is correct
73 Correct 820 ms 276988 KB Output is correct
74 Correct 796 ms 277332 KB Output is correct
75 Correct 86 ms 123084 KB Output is correct
76 Correct 1032 ms 275996 KB Output is correct
77 Correct 28 ms 108144 KB Output is correct
78 Correct 27 ms 108192 KB Output is correct
79 Correct 26 ms 108072 KB Output is correct
80 Correct 25 ms 108196 KB Output is correct
81 Correct 40 ms 108124 KB Output is correct
82 Correct 27 ms 108380 KB Output is correct
83 Correct 27 ms 108376 KB Output is correct
84 Correct 24 ms 108120 KB Output is correct
85 Correct 26 ms 108208 KB Output is correct
86 Correct 27 ms 108376 KB Output is correct
87 Correct 25 ms 108148 KB Output is correct
88 Correct 29 ms 108576 KB Output is correct
89 Correct 68 ms 108888 KB Output is correct
90 Correct 107 ms 109280 KB Output is correct
91 Correct 83 ms 108884 KB Output is correct
92 Correct 1055 ms 277864 KB Output is correct
93 Correct 912 ms 275632 KB Output is correct
94 Correct 1002 ms 283468 KB Output is correct
95 Correct 972 ms 278204 KB Output is correct
96 Correct 984 ms 278944 KB Output is correct
97 Correct 985 ms 279196 KB Output is correct
98 Correct 838 ms 284344 KB Output is correct
99 Correct 777 ms 275340 KB Output is correct
100 Correct 955 ms 284648 KB Output is correct
101 Correct 926 ms 283352 KB Output is correct
102 Correct 934 ms 284072 KB Output is correct
103 Correct 1086 ms 304116 KB Output is correct
104 Correct 837 ms 278652 KB Output is correct
105 Correct 887 ms 279868 KB Output is correct
106 Correct 1012 ms 281808 KB Output is correct
107 Correct 937 ms 282248 KB Output is correct
108 Correct 997 ms 282960 KB Output is correct
109 Correct 787 ms 273624 KB Output is correct
110 Correct 102 ms 109528 KB Output is correct
111 Correct 83 ms 108884 KB Output is correct
112 Correct 1014 ms 279500 KB Output is correct
113 Correct 1061 ms 279820 KB Output is correct
114 Correct 770 ms 279680 KB Output is correct
115 Correct 542 ms 277920 KB Output is correct
116 Correct 1022 ms 283200 KB Output is correct
117 Correct 1056 ms 284216 KB Output is correct
118 Correct 957 ms 277352 KB Output is correct
119 Correct 968 ms 277804 KB Output is correct
120 Correct 77 ms 124352 KB Output is correct
121 Correct 1016 ms 282588 KB Output is correct
122 Correct 1112 ms 282324 KB Output is correct
123 Correct 1096 ms 282024 KB Output is correct
124 Correct 949 ms 273908 KB Output is correct
125 Correct 1098 ms 282968 KB Output is correct
126 Correct 1171 ms 285412 KB Output is correct
127 Correct 1018 ms 289652 KB Output is correct
128 Correct 927 ms 289720 KB Output is correct
129 Correct 1004 ms 288776 KB Output is correct
130 Correct 952 ms 288448 KB Output is correct