# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
44275 | Nnandi | Uzastopni (COCI15_uzastopni) | C++14 | 2 ms | 700 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn=10005;
const int maxv=105;
vector<int> graf[maxn];
bool dp[maxn][maxv][maxv];
int v[maxn];
void bejar(int start, int apa, set<int> volt) {
int ez=v[start];
if(volt.count(ez)) {
return;
}
volt.insert(ez);
dp[start][ez][ez+1]=true;
vector<int> dag[maxv];
dag[ez].push_back(ez+1);
for(int s:graf[start]) {
bejar(s,start,volt);
for(int i=0;i<maxv;i++) {
for(int j=i+1;j<maxv;j++) {
if(dp[s][i][j]) {
dag[i].push_back(j);
}
}
}
}
vector<int> sor;
bool volte[maxv];
for(int i=0;i<=ez;i++) {
sor.resize(0);
memset(volte,false,maxv);
sor.push_back(i);
int it=0;
while(it<sor.size()) {
int akt=sor[it]; it++;
volte[akt]=true;
for(int s:dag[akt]) {
if(!volte[s]) {
volte[s]=true;
sor.push_back(s);
}
}
}
for(int d:sor) {
if(d>ez) {
dp[start][i][d]=true;
}
}
}
volt.erase(ez);
return;
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++) {
cin>>v[i];
}
for(int i=0;i<n-1;i++) {
int u, v;
cin>>u>>v;
u--; v--;
graf[u].push_back(v);
}
set<int> s;
bejar(0,0,s);
int sol=0;
for(int i=0;i<=v[0];i++) {
for(int j=v[0]+1;j<maxv;j++) {
if(dp[0][i][j]) {
sol++;
}
}
}
cout<<sol<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |