#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,a,b) for (lli i = (a); i <= (b); i++)
#define repa(i,a,b) for (lli i = (a); i >= (b); i--)
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 100000
#define mod 1000000007
#define pe first
#define ga second
lli n,d,a,b,g,p;
lli arr[3][MAX+2];
vector<lli> hijos[MAX+2];
pair<lli,lli> total;
lli ini(lli pos, lli padre) {
lli res = 1;
for (auto h : hijos[pos]) {
if (h == padre) continue;
a = ini(h,pos);
arr[a][pos]++;
res *= a;
}
if (res == 0) {arr[2][pos] = 1; return 1;}
else {arr[2][pos] = 0; return 0;}
}
void DFS(lli pos, lli padre,lli val) {
lli act;
arr[val][pos]++;
if (arr[0][pos] > 0) g++;
else p++;
for (auto h : hijos[pos]){
if (h == padre) continue;
arr[arr[2][h]][pos]--;
if (arr[0][pos] > 0) act = 1;
else act = 0;
arr[arr[2][h]][pos]++;
DFS(h,pos,act);
}
arr[val][pos]--;
}
pair<lli,lli> resuelve(lli pos, lli padre) {
pair<lli,lli> k,res;
res = {0,0};
for (auto h : hijos[pos]) {
if (h == padre) continue;
k = resuelve(h,pos);
arr[arr[2][h]][pos]--;
if (arr[0][pos] == 0) {
res.ga += k.pe;
res.pe += k.ga;
}
else {
res.ga += k.pe;
res.ga += k.ga;
}
arr[arr[2][h]][pos]++;
}
res.ga += p;
if (arr[0][pos] > 0) res.ga += g;
else res.pe += g;
return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> d;
rep(i,1,n-1) {
cin >> a >> b;
hijos[a].push_back(b);
hijos[b].push_back(a);
}
a = ini(1,0);
DFS(1,0,1);
total = resuelve(1,0);
total.ga %= mod;
cout << total.ga;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
9 |
Correct |
3 ms |
2636 KB |
Output is correct |
10 |
Correct |
5 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
9 |
Correct |
3 ms |
2636 KB |
Output is correct |
10 |
Correct |
5 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2636 KB |
Output is correct |
12 |
Correct |
102 ms |
11780 KB |
Output is correct |
13 |
Correct |
122 ms |
17092 KB |
Output is correct |
14 |
Correct |
89 ms |
9380 KB |
Output is correct |
15 |
Correct |
98 ms |
9672 KB |
Output is correct |
16 |
Correct |
106 ms |
9744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
9 |
Correct |
3 ms |
2636 KB |
Output is correct |
10 |
Correct |
5 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Incorrect |
3 ms |
2636 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
9 |
Correct |
3 ms |
2636 KB |
Output is correct |
10 |
Correct |
5 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2636 KB |
Output is correct |
12 |
Correct |
102 ms |
11780 KB |
Output is correct |
13 |
Correct |
122 ms |
17092 KB |
Output is correct |
14 |
Correct |
89 ms |
9380 KB |
Output is correct |
15 |
Correct |
98 ms |
9672 KB |
Output is correct |
16 |
Correct |
106 ms |
9744 KB |
Output is correct |
17 |
Correct |
2 ms |
2636 KB |
Output is correct |
18 |
Incorrect |
3 ms |
2636 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |