#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
const int mxN=200020;
int N;
int A[3][mxN];
bool Chk[3][mxN];
int par[mxN];
vector <int> u, v, a, b;
int findpar(int a)
{
return (par[a]==a ? a : par[a]=findpar(par[a]));
}
void onion(int a, int b)
{
int p=findpar(a), q=findpar(b);
if(p!=q) par[p]=q;
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
N=x.size();
for(int i=1;i<=100000;i++) for(int j=0;j<3;j++) A[j][i]=-1;
for(int i=0;i<N;i++)
{
if(x[i]==2) A[0][y[i]/2]=i;
else if(x[i]==4) A[1][y[i]/2]=i;
else A[2][y[i]/2]=i;
}
for(int i=0;i<N;i++) par[i]=i;
for(int i=1;i<100000;i++)
{
for(int j=0;j<=2;j++)
{
if(A[j][i]!=-1 && A[j][i+1]!=-1) onion(A[j][i], A[j][i+1]);
}
}
for(int i=1;i<=100000;i++)
{
for(int j=0;j<2;j++)
{
if(A[0][i]!=-1 && A[1][i]!=-1) onion(A[0][i], A[1][i]);
if(A[1][i]!=-1 && A[2][i]!=-1) onion(A[1][i], A[2][i]);
}
}
for(int i=0;i<N-1;i++)
{
if(findpar(i)!=findpar(i+1))
{
return 0;
}
}
for(int i=1;i<100000;i++)
{
for(int j=0;j<3;j++)
{
if(A[j][i]!=-1 && A[j][i+1]!=-1)
{
u.push_back(A[j][i]); v.push_back(A[j][i+1]);
b.push_back(2*i+1);
if(j==0) a.push_back(1);
else if(j==2) a.push_back(7);
else if(i%2==0) a.push_back(5);
else a.push_back(3);
}
}
}
for(int i=1;i<=100000;i++)
{
if(A[0][i]!=-1 && A[1][i]!=-1 && !Chk[0][i-1])
{
Chk[0][i]=true;
u.push_back(A[0][i]); v.push_back(A[1][i]);
a.push_back(3);
if(i%2==0) b.push_back(2*i+1);
else b.push_back(2*i-1);
}
if(A[1][i]!=-1 && A[2][i]!=-1 && !Chk[2][i-1])
{
Chk[2][i]=true;
u.push_back(A[1][i]); v.push_back(A[2][i]);
a.push_back(5);
if(i%2==0) b.push_back(2*i-1);
else b.push_back(2*i+1);
}
}
build(u, v, a, b);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
2 ms |
1484 KB |
Output is correct |
3 |
Correct |
2 ms |
1484 KB |
Output is correct |
4 |
Correct |
2 ms |
1484 KB |
Output is correct |
5 |
Correct |
2 ms |
1452 KB |
Output is correct |
6 |
Correct |
2 ms |
1484 KB |
Output is correct |
7 |
Correct |
2 ms |
1488 KB |
Output is correct |
8 |
Correct |
2 ms |
1484 KB |
Output is correct |
9 |
Correct |
61 ms |
10136 KB |
Output is correct |
10 |
Correct |
8 ms |
2508 KB |
Output is correct |
11 |
Correct |
33 ms |
6212 KB |
Output is correct |
12 |
Correct |
11 ms |
3020 KB |
Output is correct |
13 |
Correct |
10 ms |
3064 KB |
Output is correct |
14 |
Correct |
2 ms |
1484 KB |
Output is correct |
15 |
Correct |
2 ms |
1484 KB |
Output is correct |
16 |
Correct |
62 ms |
9644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
2 ms |
1484 KB |
Output is correct |
3 |
Correct |
2 ms |
1484 KB |
Output is correct |
4 |
Correct |
2 ms |
1484 KB |
Output is correct |
5 |
Correct |
2 ms |
1452 KB |
Output is correct |
6 |
Correct |
2 ms |
1484 KB |
Output is correct |
7 |
Correct |
2 ms |
1488 KB |
Output is correct |
8 |
Correct |
2 ms |
1484 KB |
Output is correct |
9 |
Correct |
61 ms |
10136 KB |
Output is correct |
10 |
Correct |
8 ms |
2508 KB |
Output is correct |
11 |
Correct |
33 ms |
6212 KB |
Output is correct |
12 |
Correct |
11 ms |
3020 KB |
Output is correct |
13 |
Correct |
10 ms |
3064 KB |
Output is correct |
14 |
Correct |
2 ms |
1484 KB |
Output is correct |
15 |
Correct |
2 ms |
1484 KB |
Output is correct |
16 |
Correct |
62 ms |
9644 KB |
Output is correct |
17 |
Correct |
2 ms |
1452 KB |
Output is correct |
18 |
Correct |
2 ms |
1484 KB |
Output is correct |
19 |
Correct |
2 ms |
1484 KB |
Output is correct |
20 |
Correct |
2 ms |
1484 KB |
Output is correct |
21 |
Correct |
2 ms |
1484 KB |
Output is correct |
22 |
Correct |
2 ms |
1484 KB |
Output is correct |
23 |
Correct |
150 ms |
19360 KB |
Output is correct |
24 |
Correct |
2 ms |
1484 KB |
Output is correct |
25 |
Correct |
3 ms |
1584 KB |
Output is correct |
26 |
Correct |
3 ms |
1484 KB |
Output is correct |
27 |
Correct |
3 ms |
1592 KB |
Output is correct |
28 |
Correct |
56 ms |
9004 KB |
Output is correct |
29 |
Correct |
87 ms |
12600 KB |
Output is correct |
30 |
Correct |
119 ms |
16000 KB |
Output is correct |
31 |
Correct |
145 ms |
19480 KB |
Output is correct |
32 |
Correct |
3 ms |
1492 KB |
Output is correct |
33 |
Correct |
2 ms |
1484 KB |
Output is correct |
34 |
Correct |
2 ms |
1456 KB |
Output is correct |
35 |
Correct |
2 ms |
1484 KB |
Output is correct |
36 |
Correct |
2 ms |
1484 KB |
Output is correct |
37 |
Correct |
2 ms |
1484 KB |
Output is correct |
38 |
Correct |
2 ms |
1484 KB |
Output is correct |
39 |
Correct |
2 ms |
1484 KB |
Output is correct |
40 |
Correct |
2 ms |
1484 KB |
Output is correct |
41 |
Correct |
2 ms |
1612 KB |
Output is correct |
42 |
Correct |
2 ms |
1484 KB |
Output is correct |
43 |
Correct |
2 ms |
1484 KB |
Output is correct |
44 |
Correct |
2 ms |
1484 KB |
Output is correct |
45 |
Correct |
63 ms |
9232 KB |
Output is correct |
46 |
Correct |
92 ms |
12416 KB |
Output is correct |
47 |
Correct |
90 ms |
12316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
2 ms |
1484 KB |
Output is correct |
3 |
Correct |
2 ms |
1484 KB |
Output is correct |
4 |
Correct |
2 ms |
1484 KB |
Output is correct |
5 |
Correct |
2 ms |
1452 KB |
Output is correct |
6 |
Correct |
2 ms |
1484 KB |
Output is correct |
7 |
Correct |
2 ms |
1488 KB |
Output is correct |
8 |
Correct |
2 ms |
1484 KB |
Output is correct |
9 |
Correct |
61 ms |
10136 KB |
Output is correct |
10 |
Correct |
8 ms |
2508 KB |
Output is correct |
11 |
Correct |
33 ms |
6212 KB |
Output is correct |
12 |
Correct |
11 ms |
3020 KB |
Output is correct |
13 |
Correct |
10 ms |
3064 KB |
Output is correct |
14 |
Correct |
2 ms |
1484 KB |
Output is correct |
15 |
Correct |
2 ms |
1484 KB |
Output is correct |
16 |
Correct |
62 ms |
9644 KB |
Output is correct |
17 |
Correct |
2 ms |
1452 KB |
Output is correct |
18 |
Correct |
2 ms |
1484 KB |
Output is correct |
19 |
Correct |
2 ms |
1484 KB |
Output is correct |
20 |
Correct |
2 ms |
1484 KB |
Output is correct |
21 |
Correct |
2 ms |
1484 KB |
Output is correct |
22 |
Correct |
2 ms |
1484 KB |
Output is correct |
23 |
Correct |
150 ms |
19360 KB |
Output is correct |
24 |
Correct |
2 ms |
1484 KB |
Output is correct |
25 |
Correct |
3 ms |
1584 KB |
Output is correct |
26 |
Correct |
3 ms |
1484 KB |
Output is correct |
27 |
Correct |
3 ms |
1592 KB |
Output is correct |
28 |
Correct |
56 ms |
9004 KB |
Output is correct |
29 |
Correct |
87 ms |
12600 KB |
Output is correct |
30 |
Correct |
119 ms |
16000 KB |
Output is correct |
31 |
Correct |
145 ms |
19480 KB |
Output is correct |
32 |
Correct |
3 ms |
1492 KB |
Output is correct |
33 |
Correct |
2 ms |
1484 KB |
Output is correct |
34 |
Correct |
2 ms |
1456 KB |
Output is correct |
35 |
Correct |
2 ms |
1484 KB |
Output is correct |
36 |
Correct |
2 ms |
1484 KB |
Output is correct |
37 |
Correct |
2 ms |
1484 KB |
Output is correct |
38 |
Correct |
2 ms |
1484 KB |
Output is correct |
39 |
Correct |
2 ms |
1484 KB |
Output is correct |
40 |
Correct |
2 ms |
1484 KB |
Output is correct |
41 |
Correct |
2 ms |
1612 KB |
Output is correct |
42 |
Correct |
2 ms |
1484 KB |
Output is correct |
43 |
Correct |
2 ms |
1484 KB |
Output is correct |
44 |
Correct |
2 ms |
1484 KB |
Output is correct |
45 |
Correct |
63 ms |
9232 KB |
Output is correct |
46 |
Correct |
92 ms |
12416 KB |
Output is correct |
47 |
Correct |
90 ms |
12316 KB |
Output is correct |
48 |
Correct |
2 ms |
1484 KB |
Output is correct |
49 |
Correct |
2 ms |
1484 KB |
Output is correct |
50 |
Correct |
2 ms |
1484 KB |
Output is correct |
51 |
Correct |
2 ms |
1484 KB |
Output is correct |
52 |
Correct |
3 ms |
1484 KB |
Output is correct |
53 |
Correct |
3 ms |
1484 KB |
Output is correct |
54 |
Correct |
2 ms |
1484 KB |
Output is correct |
55 |
Correct |
154 ms |
19700 KB |
Output is correct |
56 |
Correct |
2 ms |
1452 KB |
Output is correct |
57 |
Correct |
4 ms |
1716 KB |
Output is correct |
58 |
Correct |
7 ms |
2124 KB |
Output is correct |
59 |
Correct |
4 ms |
1740 KB |
Output is correct |
60 |
Correct |
74 ms |
10780 KB |
Output is correct |
61 |
Correct |
103 ms |
13980 KB |
Output is correct |
62 |
Correct |
125 ms |
16660 KB |
Output is correct |
63 |
Correct |
152 ms |
19732 KB |
Output is correct |
64 |
Correct |
2 ms |
1484 KB |
Output is correct |
65 |
Correct |
2 ms |
1484 KB |
Output is correct |
66 |
Correct |
2 ms |
1484 KB |
Output is correct |
67 |
Correct |
124 ms |
16532 KB |
Output is correct |
68 |
Correct |
128 ms |
16792 KB |
Output is correct |
69 |
Correct |
125 ms |
16192 KB |
Output is correct |
70 |
Correct |
3 ms |
1484 KB |
Output is correct |
71 |
Correct |
4 ms |
1612 KB |
Output is correct |
72 |
Correct |
62 ms |
8976 KB |
Output is correct |
73 |
Correct |
104 ms |
12696 KB |
Output is correct |
74 |
Correct |
127 ms |
16028 KB |
Output is correct |
75 |
Correct |
140 ms |
18584 KB |
Output is correct |
76 |
Correct |
126 ms |
16792 KB |
Output is correct |
77 |
Correct |
3 ms |
1612 KB |
Output is correct |
78 |
Correct |
4 ms |
1612 KB |
Output is correct |
79 |
Correct |
66 ms |
9328 KB |
Output is correct |
80 |
Correct |
102 ms |
13220 KB |
Output is correct |
81 |
Correct |
134 ms |
16928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
2 ms |
1484 KB |
Output is correct |
3 |
Correct |
2 ms |
1484 KB |
Output is correct |
4 |
Correct |
2 ms |
1484 KB |
Output is correct |
5 |
Correct |
2 ms |
1452 KB |
Output is correct |
6 |
Correct |
2 ms |
1484 KB |
Output is correct |
7 |
Correct |
2 ms |
1488 KB |
Output is correct |
8 |
Correct |
2 ms |
1484 KB |
Output is correct |
9 |
Correct |
61 ms |
10136 KB |
Output is correct |
10 |
Correct |
8 ms |
2508 KB |
Output is correct |
11 |
Correct |
33 ms |
6212 KB |
Output is correct |
12 |
Correct |
11 ms |
3020 KB |
Output is correct |
13 |
Correct |
10 ms |
3064 KB |
Output is correct |
14 |
Correct |
2 ms |
1484 KB |
Output is correct |
15 |
Correct |
2 ms |
1484 KB |
Output is correct |
16 |
Correct |
62 ms |
9644 KB |
Output is correct |
17 |
Incorrect |
2 ms |
1484 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
2 ms |
1484 KB |
Output is correct |
3 |
Correct |
2 ms |
1484 KB |
Output is correct |
4 |
Correct |
2 ms |
1484 KB |
Output is correct |
5 |
Correct |
2 ms |
1452 KB |
Output is correct |
6 |
Correct |
2 ms |
1484 KB |
Output is correct |
7 |
Correct |
2 ms |
1488 KB |
Output is correct |
8 |
Correct |
2 ms |
1484 KB |
Output is correct |
9 |
Correct |
61 ms |
10136 KB |
Output is correct |
10 |
Correct |
8 ms |
2508 KB |
Output is correct |
11 |
Correct |
33 ms |
6212 KB |
Output is correct |
12 |
Correct |
11 ms |
3020 KB |
Output is correct |
13 |
Correct |
10 ms |
3064 KB |
Output is correct |
14 |
Correct |
2 ms |
1484 KB |
Output is correct |
15 |
Correct |
2 ms |
1484 KB |
Output is correct |
16 |
Correct |
62 ms |
9644 KB |
Output is correct |
17 |
Incorrect |
49 ms |
6864 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
2 ms |
1484 KB |
Output is correct |
3 |
Correct |
2 ms |
1484 KB |
Output is correct |
4 |
Correct |
2 ms |
1484 KB |
Output is correct |
5 |
Correct |
2 ms |
1452 KB |
Output is correct |
6 |
Correct |
2 ms |
1484 KB |
Output is correct |
7 |
Correct |
2 ms |
1488 KB |
Output is correct |
8 |
Correct |
2 ms |
1484 KB |
Output is correct |
9 |
Correct |
61 ms |
10136 KB |
Output is correct |
10 |
Correct |
8 ms |
2508 KB |
Output is correct |
11 |
Correct |
33 ms |
6212 KB |
Output is correct |
12 |
Correct |
11 ms |
3020 KB |
Output is correct |
13 |
Correct |
10 ms |
3064 KB |
Output is correct |
14 |
Correct |
2 ms |
1484 KB |
Output is correct |
15 |
Correct |
2 ms |
1484 KB |
Output is correct |
16 |
Correct |
62 ms |
9644 KB |
Output is correct |
17 |
Correct |
2 ms |
1452 KB |
Output is correct |
18 |
Correct |
2 ms |
1484 KB |
Output is correct |
19 |
Correct |
2 ms |
1484 KB |
Output is correct |
20 |
Correct |
2 ms |
1484 KB |
Output is correct |
21 |
Correct |
2 ms |
1484 KB |
Output is correct |
22 |
Correct |
2 ms |
1484 KB |
Output is correct |
23 |
Correct |
150 ms |
19360 KB |
Output is correct |
24 |
Correct |
2 ms |
1484 KB |
Output is correct |
25 |
Correct |
3 ms |
1584 KB |
Output is correct |
26 |
Correct |
3 ms |
1484 KB |
Output is correct |
27 |
Correct |
3 ms |
1592 KB |
Output is correct |
28 |
Correct |
56 ms |
9004 KB |
Output is correct |
29 |
Correct |
87 ms |
12600 KB |
Output is correct |
30 |
Correct |
119 ms |
16000 KB |
Output is correct |
31 |
Correct |
145 ms |
19480 KB |
Output is correct |
32 |
Correct |
3 ms |
1492 KB |
Output is correct |
33 |
Correct |
2 ms |
1484 KB |
Output is correct |
34 |
Correct |
2 ms |
1456 KB |
Output is correct |
35 |
Correct |
2 ms |
1484 KB |
Output is correct |
36 |
Correct |
2 ms |
1484 KB |
Output is correct |
37 |
Correct |
2 ms |
1484 KB |
Output is correct |
38 |
Correct |
2 ms |
1484 KB |
Output is correct |
39 |
Correct |
2 ms |
1484 KB |
Output is correct |
40 |
Correct |
2 ms |
1484 KB |
Output is correct |
41 |
Correct |
2 ms |
1612 KB |
Output is correct |
42 |
Correct |
2 ms |
1484 KB |
Output is correct |
43 |
Correct |
2 ms |
1484 KB |
Output is correct |
44 |
Correct |
2 ms |
1484 KB |
Output is correct |
45 |
Correct |
63 ms |
9232 KB |
Output is correct |
46 |
Correct |
92 ms |
12416 KB |
Output is correct |
47 |
Correct |
90 ms |
12316 KB |
Output is correct |
48 |
Correct |
2 ms |
1484 KB |
Output is correct |
49 |
Correct |
2 ms |
1484 KB |
Output is correct |
50 |
Correct |
2 ms |
1484 KB |
Output is correct |
51 |
Correct |
2 ms |
1484 KB |
Output is correct |
52 |
Correct |
3 ms |
1484 KB |
Output is correct |
53 |
Correct |
3 ms |
1484 KB |
Output is correct |
54 |
Correct |
2 ms |
1484 KB |
Output is correct |
55 |
Correct |
154 ms |
19700 KB |
Output is correct |
56 |
Correct |
2 ms |
1452 KB |
Output is correct |
57 |
Correct |
4 ms |
1716 KB |
Output is correct |
58 |
Correct |
7 ms |
2124 KB |
Output is correct |
59 |
Correct |
4 ms |
1740 KB |
Output is correct |
60 |
Correct |
74 ms |
10780 KB |
Output is correct |
61 |
Correct |
103 ms |
13980 KB |
Output is correct |
62 |
Correct |
125 ms |
16660 KB |
Output is correct |
63 |
Correct |
152 ms |
19732 KB |
Output is correct |
64 |
Correct |
2 ms |
1484 KB |
Output is correct |
65 |
Correct |
2 ms |
1484 KB |
Output is correct |
66 |
Correct |
2 ms |
1484 KB |
Output is correct |
67 |
Correct |
124 ms |
16532 KB |
Output is correct |
68 |
Correct |
128 ms |
16792 KB |
Output is correct |
69 |
Correct |
125 ms |
16192 KB |
Output is correct |
70 |
Correct |
3 ms |
1484 KB |
Output is correct |
71 |
Correct |
4 ms |
1612 KB |
Output is correct |
72 |
Correct |
62 ms |
8976 KB |
Output is correct |
73 |
Correct |
104 ms |
12696 KB |
Output is correct |
74 |
Correct |
127 ms |
16028 KB |
Output is correct |
75 |
Correct |
140 ms |
18584 KB |
Output is correct |
76 |
Correct |
126 ms |
16792 KB |
Output is correct |
77 |
Correct |
3 ms |
1612 KB |
Output is correct |
78 |
Correct |
4 ms |
1612 KB |
Output is correct |
79 |
Correct |
66 ms |
9328 KB |
Output is correct |
80 |
Correct |
102 ms |
13220 KB |
Output is correct |
81 |
Correct |
134 ms |
16928 KB |
Output is correct |
82 |
Incorrect |
2 ms |
1484 KB |
Solution announced impossible, but it is possible. |
83 |
Halted |
0 ms |
0 KB |
- |