Skip to content

Commit 40176bc

Browse files
authored
Update 2581.Count-Number-of-Possible-Root-Nodes.cpp
1 parent 2b01c65 commit 40176bc

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

Tree/2581.Count-Number-of-Possible-Root-Nodes/2581.Count-Number-of-Possible-Root-Nodes.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ class Solution {
33
unordered_set<int>guess[100005];
44
int ret = 0;
55
int k;
6-
int along[100005];
7-
int against[100005];
6+
int count[100005];
87
public:
98
int rootCount(vector<vector<int>>& edges, vector<vector<int>>& guesses, int k)
109
{
@@ -21,26 +20,22 @@ class Solution {
2120

2221
dfs(0, -1);
2322

24-
dfs2(0, -1, along[0]);
23+
dfs2(0, -1, count[0]);
2524

2625
return ret;
2726
}
2827

2928
void dfs(int cur, int parent)
3029
{
31-
int count = 0;
3230
for (int nxt: next[cur])
3331
{
3432
if (nxt==parent) continue;
3533

3634
if (guess[cur].find(nxt)!=guess[cur].end())
37-
along[cur] += 1;
38-
if (guess[nxt].find(cur)!=guess[nxt].end())
39-
against[cur] += 1;
35+
count[cur] += 1;
4036

4137
dfs(nxt, cur);
42-
along[cur] += along[nxt];
43-
against[cur] += against[nxt];
38+
count[cur] += count[nxt];
4439
}
4540
}
4641

0 commit comments

Comments
 (0)