QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#675440#2384. TreeLaVuna47#AC ✓3ms3828kbC++202.3kb2024-10-25 18:35:492024-10-25 18:35:50

Judging History

This is the latest submission verdict.

  • [2024-10-25 18:35:50]
  • Judged
  • Verdict: AC
  • Time: 3ms
  • Memory: 3828kb
  • [2024-10-25 18:35:49]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef double db;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;

#ifdef ONPC
mt19937 rnd(228);
#endif

int n;
vector<bool> C;
vector<vector<int>> G;

int dfs(int v, int pr, int d)
{
	if(d == 0)
		return 0;
	int res = 0;
	if(C[v])
		++res;
	for(auto to: G[v])
	{
		if(to != pr)
			res += dfs(to, v, d-1);
	}
	return res;
}

int g(const vector<int>& verts)
{
	int D = sz(verts)-1;
	int d1 = 1;
	int d2 = D-1;
	int res = 2;
	FOR(i, 1, sz(verts)-1)
	{
		int v = verts[i];
		if(C[v])
			++res;
		for(auto to: G[v])
		{
			if(to != verts[i-1] && to != verts[i+1])
			{
				res += dfs(to, v, min(d1, d2));
			}
		}
		d1 += 1;
		d2 -= 1;
	}
	return res;
}

bool get_path(int v, int pr, int last, vector<int>& verts)
{
	verts.pb(v);
	if(v == last)
		return true;
	for(auto to: G[v])
	{
		if(to != pr)
		{
			if(get_path(to, v, last, verts))
				return true;
		}
	}
	verts.pop_back();
	return false;
}

int f(int m)
{
	int res = INT32_MAX;
	FOR(i,0,n)
	{
		FOR(j,i+1,n)
		{
			if(C[i] && C[j])
			{
				vector<int> verts;
 				get_path(i, -1, j, verts);
 				int max_m = g(verts);
 				if(max_m >= m)
					res = min(res, sz(verts)-1);
			}
		}
	}
	return res;
}

int solve()
{
	int m;
	if(!(cin >> n >> m))
		return 1;
	C = vector<bool>(n, false);
	FOR(i,0,n)
	{
		int val;
		cin >> val;
		C[i] = val;
	}
	G = vector<vector<int>>(n);
	FOR(_,0,n-1)
	{
		int u, v;
		cin >> u >> v;
		--u, --v;
		G[u].pb(v);
		G[v].pb(u);
	}
	if(m == 1)
		cout << "0\n";
	else
		cout << f(m) << '\n';
		
	return 0;
}

int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int TET = 1e9;
	// cin >> TET;
	for (int i = 1; i <= TET; i++)
	{
		if (solve())
			break;
			
		#ifdef ONPC
			cerr << "_________________________\n";
		#endif
	}
	#ifdef ONPC
			cerr << "\nfinished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
	#endif
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

input:

6 3
1 1 0 1 1 1
1 2
1 3
1 4
3 5
3 6

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

9 4
1 0 1 0 1 0 0 1 1
1 2
2 4
2 3
4 5
1 6
6 7
6 8
7 9

output:

5

result:

ok single line: '5'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

7 2
0 1 0 1 0 1 0
3 6
1 3
5 3
7 1
4 5
2 7

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

2 2
1 1
2 1

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

6 1
0 1 1 0 1 1
3 5
6 3
4 5
2 6
1 3

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

8 8
1 1 1 1 1 1 1 1
3 1
5 3
6 5
8 5
2 1
7 3
4 6

output:

5

result:

ok single line: '5'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

9 3
0 1 1 1 1 0 0 1 1
4 8
7 8
5 8
1 7
3 7
2 3
9 7
6 3

output:

2

result:

ok single line: '2'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

5 2
1 0 1 1 1
1 3
4 1
2 4
5 2

output:

1

result:

ok single line: '1'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3476kb

input:

6 3
0 1 1 0 1 1
3 2
5 3
6 5
4 2
1 5

output:

2

result:

ok single line: '2'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

10 3
0 0 1 0 0 1 1 0 1 1
5 7
4 5
8 4
2 8
3 2
10 3
1 10
9 1
6 9

output:

3

result:

ok single line: '3'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

12 2
0 0 0 0 0 1 0 1 0 0 0 0
11 7
10 7
12 10
2 12
3 2
9 10
5 3
4 12
1 5
6 12
8 2

output:

3

result:

ok single line: '3'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

14 6
1 1 1 0 1 0 1 0 1 1 0 1 1 1
3 8
14 3
6 14
12 6
10 12
7 10
5 7
9 5
11 9
1 10
4 11
13 8
2 7

output:

3

result:

ok single line: '3'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

30 6
1 0 1 1 1 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1
11 28
17 11
6 17
16 6
1 16
14 1
29 14
10 29
25 16
24 10
7 6
19 17
26 7
9 29
5 28
15 28
21 15
4 7
20 15
12 11
18 25
27 12
3 1
8 18
30 27
23 6
2 25
13 3
22 9

output:

6

result:

ok single line: '6'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

32 10
0 1 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 0 0 0 0 0 0 1 1 1
23 27
30 23
31 30
25 31
16 25
10 16
24 10
26 24
6 26
4 6
28 4
17 28
7 17
20 7
15 20
21 15
13 21
9 13
14 9
22 27
5 26
1 10
11 25
12 26
32 24
8 31
18 27
19 23
2 7
3 14
29 3

output:

7

result:

ok single line: '7'

Test #15:

score: 0
Accepted
time: 1ms
memory: 3816kb

input:

50 20
1 1 0 0 1 1 0 1 1 1 0 1 1 1 0 0 1 1 0 1 1 1 1 1 1 0 0 0 1 0 0 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 0 0 1 0
32 23
26 32
36 26
7 36
24 7
22 24
40 22
49 40
35 49
41 35
46 41
48 46
30 48
10 30
12 10
2 12
31 2
4 31
19 4
17 7
45 17
5 45
34 5
29 34
33 29
42 33
9 42
20 9
8 20
43 8
14 43
13 14
16 13
47 16
27 ...

output:

16

result:

ok single line: '16'

Test #16:

score: 0
Accepted
time: 1ms
memory: 3820kb

input:

60 8
0 0 0 1 1 1 0 0 1 0 0 1 1 0 1 1 1 0 0 1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 0 0 0 1 1 1 1 0 1 1 1 1
49 55
6 49
60 6
45 60
11 45
1 11
9 1
35 9
15 35
33 45
14 33
30 14
12 30
16 12
38 16
28 38
23 28
43 23
22 43
48 45
7 48
32 7
44 32
59 44
25 59
29 25
39 29
27 39
20 27
57 30
21 ...

output:

4

result:

ok single line: '4'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

70 40
1 1 1 1 1 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 0 1 0 1 0 1 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1
67 6
45 67
61 45
58 61
19 58
51 19
7 51
21 7
15 21
28 15
22 28
69 22
27 69
55 27
52 55
4 52
3 4
36 3
49 36
16 15
40 16
17 40
37 17
66 37
24 66
14 24
23 14...

output:

27

result:

ok single line: '27'

Test #18:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

70 10
1 1 1 1 1 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 0 1 0 1 0 1 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1
67 6
45 67
61 45
58 61
19 58
51 19
7 51
21 7
15 21
28 15
22 28
69 22
27 69
55 27
52 55
4 52
3 4
36 3
49 36
16 15
40 16
17 40
37 17
66 37
24 66
14 24
23 14...

output:

5

result:

ok single line: '5'

Test #19:

score: 0
Accepted
time: 1ms
memory: 3752kb

input:

70 25
1 1 1 1 1 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 0 1 0 1 0 1 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1
67 6
45 67
61 45
58 61
19 58
51 19
7 51
21 7
15 21
28 15
22 28
69 22
27 69
55 27
52 55
4 52
3 4
36 3
49 36
16 15
40 16
17 40
37 17
66 37
24 66
14 24
23 14...

output:

15

result:

ok single line: '15'

Test #20:

score: 0
Accepted
time: 1ms
memory: 3528kb

input:

80 15
0 0 0 1 0 1 0 0 0 1 0 0 0 0 1 1 1 1 0 0 0 1 0 0 1 0 0 0 1 1 1 0 1 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 0 0 1 1 0 0 0 0 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1
61 13
45 61
47 45
44 47
78 44
5 78
18 5
35 18
60 35
58 60
26 58
24 26
74 24
38 74
65 38
7 65
69 7
27 69
29 27
6 29
50 6
15 50
70 15
73...

output:

16

result:

ok single line: '16'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

80 3
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1
28 49
4 28
39 4
9 39
54 9
2 54
74 2
30 74
52 30
71 52
12 71
67 12
77 67
76 77
25 76
63 25
18 63
72 18
46 72
66 52
62 66
35 62
48 35
29 ...

output:

4

result:

ok single line: '4'

Test #22:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

80 30
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
28 49
4 28
39 4
9 39
54 9
2 54
74 2
30 74
52 30
71 52
12 71
67 12
77 67
76 77
25 76
63 25
18 63
72 18
46 72
66 52
62 66
35 62
48 35
29...

output:

12

result:

ok single line: '12'

Test #23:

score: 0
Accepted
time: 1ms
memory: 3532kb

input:

80 5
1 0 0 1 0 0 0 1 1 1 1 0 0 1 1 1 1 0 1 1 1 1 0 1 1 0 1 1 1 1 0 1 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 0 1 0 1 0 1 1 1 1 1 0 1 1 0 1 0 1 0 0
64 18
62 64
32 62
57 32
17 57
35 17
10 35
60 10
21 60
66 21
28 66
3 28
74 3
54 74
36 54
39 36
69 39
59 69
22 59
26 21
29 26
65 29
23 65...

output:

3

result:

ok single line: '3'

Test #24:

score: 0
Accepted
time: 1ms
memory: 3524kb

input:

100 5
0 1 1 0 0 0 1 0 0 0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 1 0 0 0 1 1 1 1 0 1 1 1 1 1 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 1 1 0 0 0 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 1
73 62
94 73
91 94
47 91
76 47
7 76
98 7
28 98
87 28
15 87
85 15
11 85
54 11
77 54
31 77
81 31
...

output:

3

result:

ok single line: '3'

Test #25:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

100 50
0 1 1 0 0 0 1 0 0 0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 1 0 0 0 1 1 1 1 0 1 1 1 1 1 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 1 1 0 0 0 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 1
73 62
94 73
91 94
47 91
76 47
7 76
98 7
28 98
87 28
15 87
85 15
11 85
54 11
77 54
31 77
81 31...

output:

58

result:

ok single line: '58'

Test #26:

score: 0
Accepted
time: 3ms
memory: 3620kb

input:

100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
73 62
94 73
91 94
47 91
76 47
7 76
98 7
28 98
87 28
15 87
85 15
11 85
54 11
77 54
31 77
81 3...

output:

60

result:

ok single line: '60'

Test #27:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

100 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
73 62
94 73
91 94
47 91
76 47
7 76
98 7
28 98
87 28
15 87
85 15
11 85
54 11
77 54
31 77
81 31
...

output:

0

result:

ok single line: '0'

Test #28:

score: 0
Accepted
time: 3ms
memory: 3484kb

input:

100 50
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
73 62
94 73
91 94
47 91
76 47
7 76
98 7
28 98
87 28
15 87
85 15
11 85
54 11
77 54
31 77
81 31...

output:

24

result:

ok single line: '24'

Test #29:

score: 0
Accepted
time: 3ms
memory: 3828kb

input:

100 10
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
73 62
94 73
91 94
47 91
76 47
7 76
98 7
28 98
87 28
15 87
85 15
11 85
54 11
77 54
31 77
81 31...

output:

5

result:

ok single line: '5'

Test #30:

score: 0
Accepted
time: 2ms
memory: 3532kb

input:

100 10
1 0 1 1 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0 1 0 1 1 0 0 0 1 1 1 0 0 0 1 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 0 1 0 1 1 0
20 38
89 20
50 89
47 50
10 47
73 10
42 73
61 42
15 61
53 15
21 53
19 21
37 19
35 37
83 35
91 ...

output:

6

result:

ok single line: '6'

Test #31:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

100 7
1 0 1 1 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0 1 0 1 1 0 0 0 1 1 1 0 0 0 1 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 0 1 0 1 1 0
20 38
89 20
50 89
47 50
10 47
73 10
42 73
61 42
15 61
53 15
21 53
19 21
37 19
35 37
83 35
91 8...

output:

4

result:

ok single line: '4'

Test #32:

score: 0
Accepted
time: 2ms
memory: 3616kb

input:

100 65
1 0 1 1 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0 1 0 1 1 0 0 0 1 1 1 0 0 0 1 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 0 1 0 1 1 0
20 38
89 20
50 89
47 50
10 47
73 10
42 73
61 42
15 61
53 15
21 53
19 21
37 19
35 37
83 35
91 ...

output:

44

result:

ok single line: '44'

Test #33:

score: 0
Accepted
time: 0ms
memory: 3500kb

input:

100 43
1 0 1 1 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0 1 0 1 1 0 0 0 1 1 1 0 0 0 1 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 0 1 0 1 1 0
20 38
89 20
50 89
47 50
10 47
73 10
42 73
61 42
15 61
53 15
21 53
19 21
37 19
35 37
83 35
91 ...

output:

29

result:

ok single line: '29'

Test #34:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

100 43
1 0 1 0 0 1 0 1 1 1 1 0 0 0 1 1 0 1 0 0 0 1 1 0 0 1 1 1 0 1 0 0 0 0 0 1 1 1 1 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 1 1 0 0 1 1 0 1 0 1 1 0 0 0 1 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 1 1 0 1 1 1 1 0 1 1 0 0 0 0 1 0
20 38
89 20
50 89
47 50
10 47
73 10
42 73
61 42
15 61
53 15
21 53
19 21
37 19
35 37
83 35
91 ...

output:

37

result:

ok single line: '37'

Test #35:

score: 0
Accepted
time: 3ms
memory: 3548kb

input:

100 2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
20 38
89 20
50 89
47 50
10 47
73 10
42 73
61 42
15 61
53 15
21 53
19 21
37 19
35 37
83 35
91 8...

output:

1

result:

ok single line: '1'

Test #36:

score: 0
Accepted
time: 2ms
memory: 3816kb

input:

100 2
1 1 1 1 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 0 0 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 0 1 1 0
20 38
89 20
50 89
47 50
10 47
73 10
42 73
61 42
15 61
53 15
21 53
19 21
37 19
35 37
83 35
91 8...

output:

1

result:

ok single line: '1'

Test #37:

score: 0
Accepted
time: 1ms
memory: 3620kb

input:

100 16
0 1 1 0 0 1 1 1 0 0 1 0 1 1 0 1 1 1 0 0 1 0 0 1 0 0 1 0 0 0 1 1 1 0 1 1 0 0 1 0 0 0 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 1 0 0 0 0 1 0 1 0 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 0 0 0 0 1 0 1 1 1 1 0 1 1 1 1 0 0 1 0
72 62
59 72
91 59
47 91
76 47
50 76
98 50
28 98
87 28
15 87
82 15
11 82
100 11
93 100
86 93
9...

output:

10

result:

ok single line: '10'

Test #38:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

1 1
1

output:

0

result:

ok single line: '0'

Test #39:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

5 1
0 0 1 0 0
1 2
2 3
4 1
5 3

output:

0

result:

ok single line: '0'

Test #40:

score: 0
Accepted
time: 0ms
memory: 3748kb

input:

5 5
1 1 1 1 1
1 2
2 3
4 3
5 3

output:

3

result:

ok single line: '3'