# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
678717 |
2023-01-06T12:49:40 Z |
gesgha |
Wells (CEOI21_wells) |
C++17 |
|
5 ms |
5076 KB |
#include <bits/stdc++.h>
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define rf(i, a, b) for (int i = a; i >= b; i--)
#define fe(x, y) for(auto& x : y)
#define fi first
#define se second
#define pb push_back
#define pw(x) (1LL << (x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
template <typename T>
using ve = vector <T>;
template <typename T>
bool umx(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T>
bool umn(T& a, T b) { return a > b ? a = b, 1 : 0; }
using ll = long long;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
const int oo = 2e9;
const ll OO = 2e18;
const int N = 2e5 + 10;
ve <int> G[N];
int up[N][22];
int timer;
int tin[N];
int tout[N];
int n, k;
int clrd[N];
int dep[N];
bool bd = 0;
void dfs1(int u, int p) {
if (u) dep[u] = dep[p] + 1;
up[u][0] = p;
tin[u] = timer++;
fr(i, 1, 20) up[u][i] = up[up[u][i - 1]][i - 1];
fe(to, G[u]) if (to != p) dfs1(to, u);
tout[u] = timer;
}
bool isupper(int u, int v) { return tin[u] <= tin[v] && tout[v] <= tout[u]; }
int lca(int u, int v) {
if (isupper(u, v)) return u;
if (isupper(v, u)) return v;
rf(i, 20, 0) if (!isupper(up[u][i], v)) u = up[u][i];
return up[u][0];
}
int mxw[N];
void dfs(int u, int p, int dst) {
mxw[u] = 1;
if (dst % k == 0) {
clrd[u] = 1;
mxw[u] = 0;
}
ve <int> v;
fe(to, G[u]) if (to != p) {
dfs(to, u, dst + 1);
if (clrd[u] == 0) {
umx(mxw[u], mxw[to] + 1);
v.pb(mxw[to]);
}
}
sort(all(v));
reverse(all(v));
if (sz(v) > 1 && v[0] + v[1] + 1 >= k) bd = 1;
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
fr(i,0, n - 2) {
int u, v; cin >> u >> v; u--; v--;
G[u].pb(v);
G[v].pb(u);
}
dfs1(0, 0);
// cout << "NO\n"; return 0;
fr(i, 0, n - 1) {
dfs(i, i, 0);
ve <int> v;
fr(j, 0, n - 1) if(clrd[j]) v.pb(j);
fr(i, 0, n - 1) clrd[i] = 0;
bool bad = 0;
if (!bd) {
fr(x, 0, sz(v) - 1) {
fr(y, x + 1, sz(v) - 1) {
int C = lca(v[x], v[y]);
if (dep[v[x]] + dep[v[y]] - 2 * dep[C] < k) {
bad = 1;
break;
}
}
if (bad) break;
}
}
// cout << i << "\n";
// fe(x, v) cout << x << " ";
if(!(bad || bd)) {
cout << "YES\n1\n";
exit(0);
}
// cout << "\n";
bd = 0;
fr(i, 0, n - 1) mxw[i] = 0;
}
cout << "NO\n0\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
4948 KB |
Output is partially correct |
2 |
Partially correct |
4 ms |
5076 KB |
Output is partially correct |
3 |
Partially correct |
2 ms |
5076 KB |
Output is partially correct |
4 |
Partially correct |
2 ms |
5076 KB |
Output is partially correct |
5 |
Partially correct |
4 ms |
5076 KB |
Output is partially correct |
6 |
Partially correct |
3 ms |
5076 KB |
Output is partially correct |
7 |
Correct |
5 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
5 ms |
5076 KB |
Output is correct |
11 |
Incorrect |
4 ms |
5076 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
4948 KB |
Output is partially correct |
2 |
Partially correct |
4 ms |
5076 KB |
Output is partially correct |
3 |
Partially correct |
2 ms |
5076 KB |
Output is partially correct |
4 |
Partially correct |
2 ms |
5076 KB |
Output is partially correct |
5 |
Partially correct |
4 ms |
5076 KB |
Output is partially correct |
6 |
Partially correct |
3 ms |
5076 KB |
Output is partially correct |
7 |
Correct |
5 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
5 ms |
5076 KB |
Output is correct |
11 |
Incorrect |
4 ms |
5076 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
4948 KB |
Output is partially correct |
2 |
Partially correct |
4 ms |
5076 KB |
Output is partially correct |
3 |
Partially correct |
2 ms |
5076 KB |
Output is partially correct |
4 |
Partially correct |
2 ms |
5076 KB |
Output is partially correct |
5 |
Partially correct |
4 ms |
5076 KB |
Output is partially correct |
6 |
Partially correct |
3 ms |
5076 KB |
Output is partially correct |
7 |
Correct |
5 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
5 ms |
5076 KB |
Output is correct |
11 |
Incorrect |
4 ms |
5076 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
4948 KB |
Output is partially correct |
2 |
Partially correct |
4 ms |
5076 KB |
Output is partially correct |
3 |
Partially correct |
2 ms |
5076 KB |
Output is partially correct |
4 |
Partially correct |
2 ms |
5076 KB |
Output is partially correct |
5 |
Partially correct |
4 ms |
5076 KB |
Output is partially correct |
6 |
Partially correct |
3 ms |
5076 KB |
Output is partially correct |
7 |
Correct |
5 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
5 ms |
5076 KB |
Output is correct |
11 |
Incorrect |
4 ms |
5076 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |