#include <bits/stdc++.h>
#include "september.h"
using namespace std;
#define ff first
#define ss second
#define sz size()
#define pb push_back
#define ll long long
#define pii pair <int, int>
const int AA = 1e5 + 5;
int par[AA], deg[AA];
bool vis[AA];
multiset <int> s;
vector <int> v[AA];
void ugrat (int x, int y) {
vis[x] = 1;
for (int i = 1; i <= y; ++i) s.insert (x);
for (int i : v[x]) {
if (par[x] == i or vis[i]) continue;
ugrat (i, y);
}
}
int solve(int N, int M, vector<int> F, vector<vector<int>> S) {
par[0] = -1;
for (int i = 1; i < N; ++i) {
par[i] = F[i];
v[i].pb (F[i]);
v[F[i]].pb (i);
}
int jogap = 0;
for (int k = 0; k <= N - 2; ++k) {
for (int i = 0; i < M; ++i) {
int j = S[i][k];
jogap++;
ugrat (j, M);
int val = k;
while (!s.empty()) {
for (int j = 0; j < M; ++j) {
if (s.find (S[j][val]) == s.end ()) {
if (!vis[S[j][val]]) {
ugrat (S[j][val], M);
s.erase (s.find (S[j][val]));
}
}
else {
s.erase (s.find (S[j][val]));
}
}
val++;
}
k = val - 1;
break;
}
}
s.clear();
for (int i = 0; i < N; ++i) {
v[i].clear();
vis[i] = 0;
}
return jogap;
}
//void taskcase() {
// int N, M;
// assert(2 == scanf("%d%d", &N, &M));
// std::vector<int> F(N);
// F[0] = -1;
// for (int i = 1; i < N; ++i)
// assert(1 == scanf("%d", &F[i]));
//
// std::vector<std::vector<int>> S(M, std::vector<int>(N - 1));
// for (int i = 0; i < M; ++i)
// for (int j = 0; j < N - 1; ++j)
// assert(1 == scanf("%d", &S[i][j]));
//
// printf("%d\n", solve(N, M, F, S));
//}
//
//int main() {
// freopen ("input.txt", "r", stdin);
// int T;
// assert(1 == scanf("%d", &T));
// while(T--) taskcase();
// return 0;
//}
//
///*
//1
//3 1
//0 0
//1 2
//ans : 2
//*/
///*
//1
//5 2
//0 0 1 1
//1 2 3 4
//4 1 2 3
//ans : 1
//*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2908 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
2 ms |
2856 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2908 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
2 ms |
2652 KB |
Output is correct |
34 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
109 ms |
10872 KB |
Output is correct |
5 |
Correct |
126 ms |
10780 KB |
Output is correct |
6 |
Correct |
112 ms |
10836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
109 ms |
10872 KB |
Output is correct |
19 |
Correct |
126 ms |
10780 KB |
Output is correct |
20 |
Correct |
112 ms |
10836 KB |
Output is correct |
21 |
Correct |
134 ms |
11948 KB |
Output is correct |
22 |
Correct |
130 ms |
10924 KB |
Output is correct |
23 |
Correct |
134 ms |
11696 KB |
Output is correct |
24 |
Correct |
121 ms |
11696 KB |
Output is correct |
25 |
Correct |
133 ms |
12200 KB |
Output is correct |
26 |
Correct |
128 ms |
11944 KB |
Output is correct |
27 |
Correct |
123 ms |
9388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
109 ms |
10872 KB |
Output is correct |
8 |
Correct |
126 ms |
10780 KB |
Output is correct |
9 |
Correct |
112 ms |
10836 KB |
Output is correct |
10 |
Correct |
109 ms |
11508 KB |
Output is correct |
11 |
Correct |
89 ms |
11468 KB |
Output is correct |
12 |
Correct |
87 ms |
12432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2908 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
2 ms |
2856 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2908 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
2 ms |
2652 KB |
Output is correct |
34 |
Correct |
2 ms |
2652 KB |
Output is correct |
35 |
Correct |
109 ms |
10872 KB |
Output is correct |
36 |
Correct |
126 ms |
10780 KB |
Output is correct |
37 |
Correct |
112 ms |
10836 KB |
Output is correct |
38 |
Correct |
134 ms |
11948 KB |
Output is correct |
39 |
Correct |
130 ms |
10924 KB |
Output is correct |
40 |
Correct |
134 ms |
11696 KB |
Output is correct |
41 |
Correct |
121 ms |
11696 KB |
Output is correct |
42 |
Correct |
133 ms |
12200 KB |
Output is correct |
43 |
Correct |
128 ms |
11944 KB |
Output is correct |
44 |
Correct |
123 ms |
9388 KB |
Output is correct |
45 |
Correct |
109 ms |
11508 KB |
Output is correct |
46 |
Correct |
89 ms |
11468 KB |
Output is correct |
47 |
Correct |
87 ms |
12432 KB |
Output is correct |
48 |
Correct |
108 ms |
13000 KB |
Output is correct |
49 |
Correct |
100 ms |
12704 KB |
Output is correct |
50 |
Correct |
101 ms |
11912 KB |
Output is correct |
51 |
Correct |
111 ms |
12744 KB |
Output is correct |
52 |
Correct |
92 ms |
12920 KB |
Output is correct |
53 |
Correct |
110 ms |
12880 KB |
Output is correct |
54 |
Correct |
94 ms |
12744 KB |
Output is correct |