# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
660208 |
2022-11-21T06:52:17 Z |
fatemetmhr |
Wells (CEOI21_wells) |
C++17 |
|
54 ms |
94304 KB |
// Lotfan komak
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
const int maxn5 = 2e6 + 10;
const int mod = 1e9 + 7;
vector <int> adj[maxn5], ed[maxn5], ver;
int h[maxn5], have[maxn5], mxx = 0, mx[maxn5];
bool mark[maxn5];
void dfs(int v, int par){
have[v]= 0;
for(auto u : adj[v]) if(u != par){
h[u] = h[v] + 1;
dfs(u, v);
have[v] = max(have[v], have[u] + 1);
}
}
void dfs2(int v){
mark[v] = true;
ver.pb(v);
for(auto u : ed[v]) if(!mark[u])
dfs2(u);
}
void dfs_check(int v, int par){
have[v] = 0;
for(auto u : adj[v]) if(u != par){
h[u] = h[v] + 1;
dfs_check(u, v);
if(par != -1)
mxx = max(mxx, have[v] + have[u] + 1);
have[v] = max(have[v], have[u] + 1);
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, k; cin >> n >> k;
for(int i = 0; i < n - 1; i++){
int a, b; cin >> a >> b;
a--; b--;
adj[a].pb(b);
adj[b].pb(a);
}
ll mul = 1;
for(int i = 0; i < n; i++){
h[i] = 0;
dfs(i, -1);
mx[i] = 0;
for(int j = 0; j < n; j++) if(h[j] % k == 0){
ed[i].pb(j);
}
int last = 0;
for(auto u : adj[i]){
mx[i] = max(mx[i], have[u] + last + 1);
last = max(last, have[u] + 1);
}
if(mx[i] < k - 1)
mul = (mul * 2) % mod;
}
ll ans = 0;
for(int i = 0; i < n; i++) if(!mark[i] && mx[i] >= k - 1){
ver.clear();
dfs2(i);
bool re = true;
if(ver.size() == 1){
mxx = 0;
h[i] = 0;
dfs_check(i, -1);
ans += (mxx < k - 1);
//cout << "aha " << i << ' ' << mxx << endl;
continue;
}
for(auto u : ver) re &= (ed[u].size() == ver.size());
ans += re;
}
ans = ans * mul % mod;
if(ans)
cout << "YES\n" << ans << '\n';
else
cout << "NO\n" << 0 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
94252 KB |
Output is correct |
2 |
Partially correct |
49 ms |
94180 KB |
Output is partially correct |
3 |
Partially correct |
45 ms |
94200 KB |
Output is partially correct |
4 |
Correct |
45 ms |
94304 KB |
Output is correct |
5 |
Partially correct |
47 ms |
94228 KB |
Output is partially correct |
6 |
Partially correct |
44 ms |
94256 KB |
Output is partially correct |
7 |
Correct |
47 ms |
94248 KB |
Output is correct |
8 |
Correct |
44 ms |
94244 KB |
Output is correct |
9 |
Correct |
54 ms |
94228 KB |
Output is correct |
10 |
Correct |
47 ms |
94284 KB |
Output is correct |
11 |
Incorrect |
47 ms |
94236 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
94252 KB |
Output is correct |
2 |
Partially correct |
49 ms |
94180 KB |
Output is partially correct |
3 |
Partially correct |
45 ms |
94200 KB |
Output is partially correct |
4 |
Correct |
45 ms |
94304 KB |
Output is correct |
5 |
Partially correct |
47 ms |
94228 KB |
Output is partially correct |
6 |
Partially correct |
44 ms |
94256 KB |
Output is partially correct |
7 |
Correct |
47 ms |
94248 KB |
Output is correct |
8 |
Correct |
44 ms |
94244 KB |
Output is correct |
9 |
Correct |
54 ms |
94228 KB |
Output is correct |
10 |
Correct |
47 ms |
94284 KB |
Output is correct |
11 |
Incorrect |
47 ms |
94236 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
94252 KB |
Output is correct |
2 |
Partially correct |
49 ms |
94180 KB |
Output is partially correct |
3 |
Partially correct |
45 ms |
94200 KB |
Output is partially correct |
4 |
Correct |
45 ms |
94304 KB |
Output is correct |
5 |
Partially correct |
47 ms |
94228 KB |
Output is partially correct |
6 |
Partially correct |
44 ms |
94256 KB |
Output is partially correct |
7 |
Correct |
47 ms |
94248 KB |
Output is correct |
8 |
Correct |
44 ms |
94244 KB |
Output is correct |
9 |
Correct |
54 ms |
94228 KB |
Output is correct |
10 |
Correct |
47 ms |
94284 KB |
Output is correct |
11 |
Incorrect |
47 ms |
94236 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
94252 KB |
Output is correct |
2 |
Partially correct |
49 ms |
94180 KB |
Output is partially correct |
3 |
Partially correct |
45 ms |
94200 KB |
Output is partially correct |
4 |
Correct |
45 ms |
94304 KB |
Output is correct |
5 |
Partially correct |
47 ms |
94228 KB |
Output is partially correct |
6 |
Partially correct |
44 ms |
94256 KB |
Output is partially correct |
7 |
Correct |
47 ms |
94248 KB |
Output is correct |
8 |
Correct |
44 ms |
94244 KB |
Output is correct |
9 |
Correct |
54 ms |
94228 KB |
Output is correct |
10 |
Correct |
47 ms |
94284 KB |
Output is correct |
11 |
Incorrect |
47 ms |
94236 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |