# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
643371 |
2022-09-21T22:32:09 Z |
Pajaraja |
Jail (JOI22_jail) |
C++17 |
|
662 ms |
580332 KB |
#include <bits/stdc++.h>
#define MAXN 120007
#define MAXL 19
using namespace std;
vector<int> g[MAXN],v[2*MAXL*MAXN];
int p[MAXL][MAXN],ind[2][MAXL][MAXN],in[MAXN],out[MAXN],t,deg[MAXN];
void dfs(int s,int f)
{
p[0][s]=f;
in[s]=++t;
for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfs(g[s][i],s);
out[s]=t;
}
bool insub(int uu,int vv) {return in[uu]<=in[vv] && out[uu]>=out[vv];} //Jel v insub u
int oneunder(int uu,int vv)
{
for(int i=MAXL-1;i>=0;i--) if(!insub(p[i][uu],vv)) uu=p[i][uu];
return uu;
}
int lca(int uu,int vv)
{
if(insub(uu,vv)) return uu;
if(insub(vv,uu)) return vv;
return p[0][oneunder(uu,vv)];
}
void dostuff(int uu,int vv,int type,int br)
{
for(int i=MAXL-1;i>=0;i--) if(!insub(p[i][uu],vv))
{
if(type==0) v[br].push_back(ind[0][i][uu]);
else v[ind[1][i][uu]].push_back(br);
uu=p[i][uu];
}
if(type==0) v[br].push_back(ind[0][0][uu]);
else v[ind[1][0][uu]].push_back(br);
if(type==0) v[br].push_back(ind[0][0][vv]);
else v[ind[1][0][vv]].push_back(br);
}
int main()
{
int q;
scanf("%d",&q);
while(q--)
{
int n,m;
scanf("%d",&n);
for(int i=1;i<n;i++)
{
int t1,t2;
scanf("%d %d",&t1,&t2);
g[t1].push_back(t2);
g[t2].push_back(t1);
}
dfs(1,1); t=0;
int c=2*n,br=0;
for(int i=1;i<=n;i++) ind[0][0][i]=i;
for(int i=1;i<=n;i++) ind[1][0][i]=n+i;
for(int j=1;j<MAXL;j++) for(int i=1;i<=n;i++)
{
p[j][i]=p[j-1][p[j-1][i]];
c++;
ind[0][j][i]=c;
v[c].push_back(ind[0][j-1][i]);
v[c].push_back(ind[0][j-1][p[j-1][i]]);
c++;
ind[1][j][i]=c;
v[ind[1][j-1][i]].push_back(c);
v[ind[1][j-1][p[j-1][i]]].push_back(c);
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
c++;
int s,e;
scanf("%d%d",&s,&e);
v[s].push_back(c);
v[c].push_back(n+e);
int lc=lca(s,e);
if(lc!=s && lc!=e)
{
dostuff(p[0][s],lc,0,c);
dostuff(e,oneunder(e,lc),0,c);
dostuff(p[0][e],lc,1,c);
dostuff(s,oneunder(s,lc),1,c);
}
if(lc==s)
{
dostuff(e,oneunder(e,s),0,c);
dostuff(p[0][e],s,1,c);
}
if(lc==e)
{
dostuff(s,oneunder(s,e),1,c);
dostuff(p[0][s],e,0,c);
}
}
queue<int> q;
for(int i=1;i<=c;i++) deg[i]=0;
for(int i=1;i<=c;i++) for(int j=0;j<v[i].size();j++) deg[v[i][j]]++;
for(int i=1;i<=c;i++) if(deg[i]==0) q.push(i);
//for(int i=1;i<=c;i++) for(int j=0;j<v[i].size();j++) printf("%d %d\n",i,v[i][j]);
while(!q.empty())
{
br++;
int s=q.front(); q.pop();
for(int i=0;i<v[s].size();i++) {deg[v[s][i]]--; if(deg[v[s][i]]==0) q.push(v[s][i]);}
}
//printf("%d %d\n",c,br);
if(br==c) printf("Yes\n");
else printf("No\n");
for(int i=1;i<=c;i++) v[i].clear();
for(int i=1;i<=n;i++) g[i].clear();
}
}
Compilation message
jail.cpp: In function 'void dfs(int, int)':
jail.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfs(g[s][i],s);
| ~^~~~~~~~~~~~
jail.cpp: In function 'int main()':
jail.cpp:99:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | for(int i=1;i<=c;i++) for(int j=0;j<v[i].size();j++) deg[v[i][j]]++;
| ~^~~~~~~~~~~~
jail.cpp:106:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for(int i=0;i<v[s].size();i++) {deg[v[s][i]]--; if(deg[v[s][i]]==0) q.push(v[s][i]);}
| ~^~~~~~~~~~~~
jail.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d",&q);
| ~~~~~^~~~~~~~~
jail.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
jail.cpp:50:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%d %d",&t1,&t2);
| ~~~~~^~~~~~~~~~~~~~~~~
jail.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d",&m);
| ~~~~~^~~~~~~~~
jail.cpp:75:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | scanf("%d%d",&s,&e);
| ~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
110484 KB |
Output is correct |
2 |
Correct |
50 ms |
110476 KB |
Output is correct |
3 |
Correct |
49 ms |
110392 KB |
Output is correct |
4 |
Correct |
127 ms |
111060 KB |
Output is correct |
5 |
Correct |
222 ms |
111436 KB |
Output is correct |
6 |
Correct |
57 ms |
110924 KB |
Output is correct |
7 |
Correct |
65 ms |
110848 KB |
Output is correct |
8 |
Correct |
60 ms |
110900 KB |
Output is correct |
9 |
Correct |
351 ms |
121896 KB |
Output is correct |
10 |
Runtime error |
662 ms |
557796 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
110412 KB |
Output is correct |
2 |
Correct |
56 ms |
110488 KB |
Output is correct |
3 |
Correct |
63 ms |
110852 KB |
Output is correct |
4 |
Correct |
65 ms |
110872 KB |
Output is correct |
5 |
Correct |
65 ms |
110944 KB |
Output is correct |
6 |
Correct |
65 ms |
110832 KB |
Output is correct |
7 |
Correct |
64 ms |
110924 KB |
Output is correct |
8 |
Correct |
65 ms |
110916 KB |
Output is correct |
9 |
Correct |
63 ms |
110884 KB |
Output is correct |
10 |
Correct |
64 ms |
110936 KB |
Output is correct |
11 |
Correct |
65 ms |
110916 KB |
Output is correct |
12 |
Correct |
59 ms |
110848 KB |
Output is correct |
13 |
Correct |
60 ms |
110884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
110412 KB |
Output is correct |
2 |
Correct |
56 ms |
110488 KB |
Output is correct |
3 |
Correct |
63 ms |
110852 KB |
Output is correct |
4 |
Correct |
65 ms |
110872 KB |
Output is correct |
5 |
Correct |
65 ms |
110944 KB |
Output is correct |
6 |
Correct |
65 ms |
110832 KB |
Output is correct |
7 |
Correct |
64 ms |
110924 KB |
Output is correct |
8 |
Correct |
65 ms |
110916 KB |
Output is correct |
9 |
Correct |
63 ms |
110884 KB |
Output is correct |
10 |
Correct |
64 ms |
110936 KB |
Output is correct |
11 |
Correct |
65 ms |
110916 KB |
Output is correct |
12 |
Correct |
59 ms |
110848 KB |
Output is correct |
13 |
Correct |
60 ms |
110884 KB |
Output is correct |
14 |
Correct |
54 ms |
110448 KB |
Output is correct |
15 |
Correct |
52 ms |
110492 KB |
Output is correct |
16 |
Correct |
61 ms |
110924 KB |
Output is correct |
17 |
Correct |
62 ms |
110924 KB |
Output is correct |
18 |
Correct |
64 ms |
111016 KB |
Output is correct |
19 |
Correct |
54 ms |
110396 KB |
Output is correct |
20 |
Correct |
64 ms |
110960 KB |
Output is correct |
21 |
Correct |
64 ms |
110916 KB |
Output is correct |
22 |
Correct |
63 ms |
110904 KB |
Output is correct |
23 |
Correct |
56 ms |
110436 KB |
Output is correct |
24 |
Correct |
57 ms |
110704 KB |
Output is correct |
25 |
Correct |
66 ms |
110956 KB |
Output is correct |
26 |
Correct |
58 ms |
110840 KB |
Output is correct |
27 |
Correct |
76 ms |
110812 KB |
Output is correct |
28 |
Correct |
59 ms |
110532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
110412 KB |
Output is correct |
2 |
Correct |
56 ms |
110488 KB |
Output is correct |
3 |
Correct |
63 ms |
110852 KB |
Output is correct |
4 |
Correct |
65 ms |
110872 KB |
Output is correct |
5 |
Correct |
65 ms |
110944 KB |
Output is correct |
6 |
Correct |
65 ms |
110832 KB |
Output is correct |
7 |
Correct |
64 ms |
110924 KB |
Output is correct |
8 |
Correct |
65 ms |
110916 KB |
Output is correct |
9 |
Correct |
63 ms |
110884 KB |
Output is correct |
10 |
Correct |
64 ms |
110936 KB |
Output is correct |
11 |
Correct |
65 ms |
110916 KB |
Output is correct |
12 |
Correct |
59 ms |
110848 KB |
Output is correct |
13 |
Correct |
60 ms |
110884 KB |
Output is correct |
14 |
Correct |
54 ms |
110448 KB |
Output is correct |
15 |
Correct |
52 ms |
110492 KB |
Output is correct |
16 |
Correct |
61 ms |
110924 KB |
Output is correct |
17 |
Correct |
62 ms |
110924 KB |
Output is correct |
18 |
Correct |
64 ms |
111016 KB |
Output is correct |
19 |
Correct |
54 ms |
110396 KB |
Output is correct |
20 |
Correct |
64 ms |
110960 KB |
Output is correct |
21 |
Correct |
64 ms |
110916 KB |
Output is correct |
22 |
Correct |
63 ms |
110904 KB |
Output is correct |
23 |
Correct |
56 ms |
110436 KB |
Output is correct |
24 |
Correct |
57 ms |
110704 KB |
Output is correct |
25 |
Correct |
66 ms |
110956 KB |
Output is correct |
26 |
Correct |
58 ms |
110840 KB |
Output is correct |
27 |
Correct |
76 ms |
110812 KB |
Output is correct |
28 |
Correct |
59 ms |
110532 KB |
Output is correct |
29 |
Correct |
66 ms |
110956 KB |
Output is correct |
30 |
Correct |
68 ms |
111172 KB |
Output is correct |
31 |
Correct |
65 ms |
110864 KB |
Output is correct |
32 |
Correct |
67 ms |
110972 KB |
Output is correct |
33 |
Correct |
65 ms |
110956 KB |
Output is correct |
34 |
Correct |
64 ms |
110796 KB |
Output is correct |
35 |
Correct |
64 ms |
110884 KB |
Output is correct |
36 |
Correct |
68 ms |
110956 KB |
Output is correct |
37 |
Correct |
61 ms |
110856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
110412 KB |
Output is correct |
2 |
Correct |
56 ms |
110488 KB |
Output is correct |
3 |
Correct |
63 ms |
110852 KB |
Output is correct |
4 |
Correct |
65 ms |
110872 KB |
Output is correct |
5 |
Correct |
65 ms |
110944 KB |
Output is correct |
6 |
Correct |
65 ms |
110832 KB |
Output is correct |
7 |
Correct |
64 ms |
110924 KB |
Output is correct |
8 |
Correct |
65 ms |
110916 KB |
Output is correct |
9 |
Correct |
63 ms |
110884 KB |
Output is correct |
10 |
Correct |
64 ms |
110936 KB |
Output is correct |
11 |
Correct |
65 ms |
110916 KB |
Output is correct |
12 |
Correct |
59 ms |
110848 KB |
Output is correct |
13 |
Correct |
60 ms |
110884 KB |
Output is correct |
14 |
Correct |
54 ms |
110448 KB |
Output is correct |
15 |
Correct |
52 ms |
110492 KB |
Output is correct |
16 |
Correct |
61 ms |
110924 KB |
Output is correct |
17 |
Correct |
62 ms |
110924 KB |
Output is correct |
18 |
Correct |
64 ms |
111016 KB |
Output is correct |
19 |
Correct |
54 ms |
110396 KB |
Output is correct |
20 |
Correct |
64 ms |
110960 KB |
Output is correct |
21 |
Correct |
64 ms |
110916 KB |
Output is correct |
22 |
Correct |
63 ms |
110904 KB |
Output is correct |
23 |
Correct |
56 ms |
110436 KB |
Output is correct |
24 |
Correct |
57 ms |
110704 KB |
Output is correct |
25 |
Correct |
66 ms |
110956 KB |
Output is correct |
26 |
Correct |
58 ms |
110840 KB |
Output is correct |
27 |
Correct |
76 ms |
110812 KB |
Output is correct |
28 |
Correct |
59 ms |
110532 KB |
Output is correct |
29 |
Correct |
66 ms |
110956 KB |
Output is correct |
30 |
Correct |
68 ms |
111172 KB |
Output is correct |
31 |
Correct |
65 ms |
110864 KB |
Output is correct |
32 |
Correct |
67 ms |
110972 KB |
Output is correct |
33 |
Correct |
65 ms |
110956 KB |
Output is correct |
34 |
Correct |
64 ms |
110796 KB |
Output is correct |
35 |
Correct |
64 ms |
110884 KB |
Output is correct |
36 |
Correct |
68 ms |
110956 KB |
Output is correct |
37 |
Correct |
61 ms |
110856 KB |
Output is correct |
38 |
Correct |
398 ms |
121684 KB |
Output is correct |
39 |
Runtime error |
622 ms |
579928 KB |
Execution killed with signal 11 |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
110540 KB |
Output is correct |
2 |
Correct |
65 ms |
110504 KB |
Output is correct |
3 |
Correct |
56 ms |
110508 KB |
Output is correct |
4 |
Correct |
57 ms |
110452 KB |
Output is correct |
5 |
Correct |
96 ms |
110568 KB |
Output is correct |
6 |
Correct |
66 ms |
110844 KB |
Output is correct |
7 |
Correct |
76 ms |
110924 KB |
Output is correct |
8 |
Correct |
57 ms |
110412 KB |
Output is correct |
9 |
Correct |
58 ms |
110488 KB |
Output is correct |
10 |
Correct |
57 ms |
110696 KB |
Output is correct |
11 |
Correct |
57 ms |
110476 KB |
Output is correct |
12 |
Correct |
64 ms |
110912 KB |
Output is correct |
13 |
Correct |
169 ms |
111240 KB |
Output is correct |
14 |
Correct |
290 ms |
111452 KB |
Output is correct |
15 |
Correct |
229 ms |
111312 KB |
Output is correct |
16 |
Runtime error |
615 ms |
580332 KB |
Execution killed with signal 11 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
110484 KB |
Output is correct |
2 |
Correct |
50 ms |
110476 KB |
Output is correct |
3 |
Correct |
49 ms |
110392 KB |
Output is correct |
4 |
Correct |
127 ms |
111060 KB |
Output is correct |
5 |
Correct |
222 ms |
111436 KB |
Output is correct |
6 |
Correct |
57 ms |
110924 KB |
Output is correct |
7 |
Correct |
65 ms |
110848 KB |
Output is correct |
8 |
Correct |
60 ms |
110900 KB |
Output is correct |
9 |
Correct |
351 ms |
121896 KB |
Output is correct |
10 |
Runtime error |
662 ms |
557796 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |