#include <bits/stdc++.h>
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fir first
#define sec second
#define pdd pair<long double, long double>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ld long double
#define pmax pair<__int128, __int128>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
int dx[4]= {0, 1, 0, -1}, dy[4]= {1, 0, -1, 0};
int ddx[8]={1, 1, 0, -1, -1, -1, 0, 1}, ddy[8]={0, 1, 1, 1, 0, -1, -1, -1};
const int mxN=100025;
const int mxM=300005;
const int mxK=1000000000;
const ll MOD=1000'000'007;
const ll INF=1000000000000000005;
ll N, D;
vector <int> v[mxN];
ll outw[mxN];
ll downw[mxN], upw[mxN];
ll numw;
void dfs_downw(int now, int pre)
{
for(int nxt : v[now]) if(nxt!=pre)
{
dfs_downw(nxt, now);
}
downw[now]=(outw[now]==0 ? 1 : 0);
if(now!=1) outw[pre]+=downw[now];
}
void dfs_upw(int now, int pre)
{
if(now!=1)
{
upw[now]=(outw[pre]-downw[now]==0 ? 1 : 0);
outw[now]+=upw[now];
}
for(int nxt : v[now]) if(nxt!=pre)
{
dfs_upw(nxt, now);
}
}
int main()
{
gibon
cin >> N >> D;
for(int i=1;i<N;i++)
{
int a, b; cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
int ans=0;
for(int i=1;i<=N;i++)
{
for(int j=1;j<=N;j++)
{
for(int k=1;k<=N;k++) v[N+k].clear();
for(int i=1;i<=2*N;i++) downw[i]=upw[i]=outw[i]=0;
for(int k=1;k<=N;k++)
{
for(int ele : v[k]) v[N+k].push_back(N+ele);
}
v[i].push_back(N+j);
v[N+j].push_back(i);
dfs_downw(1, -1);
dfs_upw(1, -1);
if(outw[1]>=1) ans++;
v[i].pop_back();
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Execution timed out |
1086 ms |
2776 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
64 ms |
2644 KB |
Output is correct |
3 |
Correct |
62 ms |
2688 KB |
Output is correct |
4 |
Correct |
50 ms |
2644 KB |
Output is correct |
5 |
Correct |
65 ms |
2644 KB |
Output is correct |
6 |
Correct |
61 ms |
2684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
64 ms |
2644 KB |
Output is correct |
3 |
Correct |
62 ms |
2688 KB |
Output is correct |
4 |
Correct |
50 ms |
2644 KB |
Output is correct |
5 |
Correct |
65 ms |
2644 KB |
Output is correct |
6 |
Correct |
61 ms |
2684 KB |
Output is correct |
7 |
Execution timed out |
1094 ms |
2936 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
64 ms |
2644 KB |
Output is correct |
3 |
Correct |
62 ms |
2688 KB |
Output is correct |
4 |
Correct |
50 ms |
2644 KB |
Output is correct |
5 |
Correct |
65 ms |
2644 KB |
Output is correct |
6 |
Correct |
61 ms |
2684 KB |
Output is correct |
7 |
Execution timed out |
1094 ms |
2936 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
64 ms |
2644 KB |
Output is correct |
3 |
Correct |
62 ms |
2688 KB |
Output is correct |
4 |
Correct |
50 ms |
2644 KB |
Output is correct |
5 |
Correct |
65 ms |
2644 KB |
Output is correct |
6 |
Correct |
61 ms |
2684 KB |
Output is correct |
7 |
Execution timed out |
1094 ms |
2936 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
64 ms |
2644 KB |
Output is correct |
3 |
Correct |
62 ms |
2688 KB |
Output is correct |
4 |
Correct |
50 ms |
2644 KB |
Output is correct |
5 |
Correct |
65 ms |
2644 KB |
Output is correct |
6 |
Correct |
61 ms |
2684 KB |
Output is correct |
7 |
Execution timed out |
1094 ms |
2936 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Execution timed out |
1086 ms |
2776 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |