# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
476901 | ntabc05101 | Uzastopni (COCI15_uzastopni) | C++14 | 152 ms | 24644 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define taskname ""
const int mxN = 10005;
const int mxK = 105;
int n, v[mxN + 1];
vector< array<int, 2> > s[mxN + 1];
vector<int> q[mxK + 1];
bitset<mxK + 1> f[mxN + 1][mxK + 1];
vector<int> adj[mxN + 1];
void dfs(int u) {
for (auto &to: adj[u]) {
dfs(to);
}
for (int i = 1; i <= mxK; i++) {
q[i].clear();
}
for (auto &to: adj[u]) {
for (auto &z: s[to]) {
q[z[0]].push_back(z[1]);
}
}
for (int lo = mxK; lo; lo--) {
if (lo == v[u]) {
f[u][lo] |= f[u][lo + 1];
f[u][lo].set(lo);
}
else {
for (auto &hi: q[lo]) {
if (hi < v[u] || lo > v[u]) {
f[u][lo] |= f[u][hi + 1];
f[u][lo].set(hi);
}
}
}
for (int hi = mxK; hi; hi--) {
if (f[u][lo].test(hi) && v[u] >= lo && v[u] <= hi) {
s[u].push_back({lo, hi});
}
}
}
}
int main() {
if (fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
else {
if (fopen(taskname".in", "r")) {
freopen(taskname".in", "r", stdin);
freopen(taskname".out", "w", stdout);
}
}
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
for (int i = 0, a, b; i < n - 1; i++) {
cin >> a >> b; a--; b--;
adj[a].push_back(b);
}
dfs(0);
cout << s[0].size() << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |