-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCellRemoval.cpp
58 lines (48 loc) · 1014 Bytes
/
CellRemoval.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
using namespace std;
class CellRemoval {
public:
int ret;
vector <int> parent;
int deletedCell;
int r(int pos) {
if (pos == -1) {
ret++;
return 0;
} else if (pos == deletedCell) {
return 0;
}
r(parent[pos]);
return 0;
}
int cellsLeft(vector <int> _parent, int _deletedCell) {
ret = 0;
parent = _parent;
deletedCell = _deletedCell;
int leafs[parent.size()];
memset(leafs, 0, sizeof(leafs));
for (int i=0; i<parent.size(); i++)
if (parent[i] != -1)
leafs[parent[i]]++;
for (int i=0; i<parent.size(); i++)
if (leafs[i] == 0)
r(i);
return ret;
}
};
// Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor