| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 321217 | georgerapeanu | Pastiri (COI20_pastiri) | C++11 | 805 ms | 80720 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 500005;
int n,k;
vector<int> graph[NMAX + 5];
queue<int> q;
int dist[NMAX + 5];
int viz[NMAX + 5];
int highest[NMAX + 5];
int lvl[NMAX + 5];
void predfs(int nod,int tata,int mx,int bst){
    lvl[nod] = 1 + lvl[tata];
    if(mx < lvl[nod] + dist[nod]){
        mx = lvl[nod] + dist[nod];
        bst = nod;
    }
    highest[nod] = bst;
    for(auto it:graph[nod]){
        if(it == tata){
            continue;
        }
        predfs(it,nod,mx,bst);
    }
}
void dfs_cover(int nod){
    viz[nod] = true;
    for(auto it:graph[nod]){
        if(viz[it] == 0 && dist[nod] == 1 + dist[it]){
            dfs_cover(it);
        }
    }
}
int main(){
    scanf("%d %d",&n,&k);
    for(int i = 1;i < n;i++){
        int a,b;
        scanf("%d %d",&a,&b);
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<int> sheeps;
    for(int i = 1;i <= k;i++){
        int nod;
        scanf("%d",&nod);
        q.push(nod);
        dist[nod] = 1;
        sheeps.push_back(nod);
    }
    while(q.empty() == false){
        int nod = q.front();
        q.pop();
        for(auto it:graph[nod]){
            if(dist[it] == 0){
                dist[it] = dist[nod] + 1;
                q.push(it);
            }
        }
    }
    predfs(1,0,-1,-1);
    sort(sheeps.begin(),sheeps.end(),[&](int a,int b){return lvl[a] > lvl[b];});
    vector<int> ans;
    for(auto it:sheeps){
        if(viz[it] == 0){
            dfs_cover(highest[it]);
            ans.push_back(highest[it]);
        }
    }
    sort(ans.begin(),ans.end());
    printf("%d\n",(int)ans.size());
    for(auto it:ans){
        printf("%d ",it);
    }
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
