#include "bits/stdc++.h"
using namespace std;
#define ar array
typedef int64_t ll;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
vector<int> edges[N];
int dp[N], sub[N], up[N];
int is[N][2], cnt[N];
ar<int, 2> C{};
void dfs(int u, int p = -1){
cnt[u] = 1;
for(auto x : edges[u]){
if(x == p) continue;
dfs(x, u);
if(dp[x] == 0) dp[u] = 1;
cnt[u] += cnt[x];
}
sub[u] = dp[u];
}
void re(int u, int p = -1){
if(up[u] == 0) dp[u] = 1;
ar<int, 2> c {};
c[up[u]]++;
for(auto x : edges[u]){
if(x == p) continue;
c[dp[x]]++;
}
for(auto x : edges[u]){
if(x == p) continue;
c[dp[x]]--;
if(c[0]) up[x] = 1;
re(x, u);
}
}
int n;
void dfs2(int u, int p = -1){
int f = 0, v = -1;
for(auto x : edges[u]){
if(x == p) continue;
dfs2(x, u);
if(!sub[x]){
f++, v = x;
}
}
if(f > 1){
is[u][1] = cnt[u] * 1ll * n % mod;
} else if(f == 1) {
is[u][1] = (cnt[u] - cnt[v]) * 1ll * n % mod;
is[u][1] = (is[u][1] + is[v][0]), is[u][0] = (is[u][0] + is[v][1]);
} else {
is[u][1] = C[0], is[u][0] = C[1];
for(auto x : edges[u]){
if(x == p) continue;
is[u][0] = (is[u][0] + is[x][1]), is[u][1] = (is[u][1] + is[x][0]);
}
}
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int d; cin>>n>>d;
for(int i=1;i<n;i++){
int a, b; cin>>a>>b;
edges[a].push_back(b);
edges[b].push_back(a);
edges[a + n].push_back(b + n);
edges[b + n].push_back(a + n);
}
int res = 0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
edges[i].push_back(j + n);
memset(dp, 0, sizeof dp);
dfs(1);
if(dp[1]){
res++;
}
edges[i].pop_back();
}
}
cout<<res<<"\n";
}
/*
4 1
1 2
2 3
2 4
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3028 KB |
Output is correct |
2 |
Execution timed out |
1083 ms |
3028 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
3028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3048 KB |
Output is correct |
2 |
Correct |
165 ms |
3060 KB |
Output is correct |
3 |
Correct |
161 ms |
3092 KB |
Output is correct |
4 |
Correct |
141 ms |
3156 KB |
Output is correct |
5 |
Correct |
126 ms |
3060 KB |
Output is correct |
6 |
Correct |
154 ms |
3064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3048 KB |
Output is correct |
2 |
Correct |
165 ms |
3060 KB |
Output is correct |
3 |
Correct |
161 ms |
3092 KB |
Output is correct |
4 |
Correct |
141 ms |
3156 KB |
Output is correct |
5 |
Correct |
126 ms |
3060 KB |
Output is correct |
6 |
Correct |
154 ms |
3064 KB |
Output is correct |
7 |
Execution timed out |
1064 ms |
3228 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3048 KB |
Output is correct |
2 |
Correct |
165 ms |
3060 KB |
Output is correct |
3 |
Correct |
161 ms |
3092 KB |
Output is correct |
4 |
Correct |
141 ms |
3156 KB |
Output is correct |
5 |
Correct |
126 ms |
3060 KB |
Output is correct |
6 |
Correct |
154 ms |
3064 KB |
Output is correct |
7 |
Execution timed out |
1064 ms |
3228 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3048 KB |
Output is correct |
2 |
Correct |
165 ms |
3060 KB |
Output is correct |
3 |
Correct |
161 ms |
3092 KB |
Output is correct |
4 |
Correct |
141 ms |
3156 KB |
Output is correct |
5 |
Correct |
126 ms |
3060 KB |
Output is correct |
6 |
Correct |
154 ms |
3064 KB |
Output is correct |
7 |
Execution timed out |
1064 ms |
3228 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3048 KB |
Output is correct |
2 |
Correct |
165 ms |
3060 KB |
Output is correct |
3 |
Correct |
161 ms |
3092 KB |
Output is correct |
4 |
Correct |
141 ms |
3156 KB |
Output is correct |
5 |
Correct |
126 ms |
3060 KB |
Output is correct |
6 |
Correct |
154 ms |
3064 KB |
Output is correct |
7 |
Execution timed out |
1064 ms |
3228 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3028 KB |
Output is correct |
2 |
Execution timed out |
1083 ms |
3028 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |