Submission #759067

# Submission time Handle Problem Language Result Execution time Memory
759067 2023-06-15T17:58:18 Z Ronin13 Pastiri (COI20_pastiri) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 500001;

int x[nmax], d[nmax];
//bool active[nmax];
int dp[nmax];

vector <vector <int> > g(nmax);


vector <int> ans;

void DFS(int v, int e){
    for(int to : g[v]){
        if(to == e) continue;
        DFS(to, v);
        d[v] = max(d[v], d[to] + 1);
        dp[v] = max(dp[v], dp[to] - 1);
    }
    if(d[v] < 0)
        return;
    if(x[e] == d[v] + 1){
        if(dp[v] >= d[v]) d[v] = -1e9;
        return;
    }
    if(dp[v] >= d[v]){
        d[v] = -1e9;
        return;
    }
    dp[v] = d[v];
    d[v] = -1e9;
    ans.pb(v);
}

int main(){
    //ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k;
    scanf("%d%d",&n, &k);
    for(int i = 1; i < n; i++){
        int u, v; scanf("%d%d", &u, &v);
        g[u].pb(v);
        g[v].pb(u);
    }
    //int k; cin >> k;
    for(int i = 1; i <= n; i++){
        x[i] = 1e9;
        d[i] = -1e9;
        dp[i] = -1e9;
    }
    queue <int> q;
    for(int i = 1; i <= k; ++i){
        int y; scanf("%d", &y);
        q.push(y);
        active[y] = true;
        x[y] = d[y] = 0;
    }
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(int to : g[v]){
            if(x[to] <= x[v]) continue;
            x[to] = x[v] + 1;
            q.push(to);
        }
    }
    x[0] = 1e9;
    DFS(1, 0);

    printf("%d\n", ans.size()); //ans.size() << "\n";
   // sort(ans.begin(), ans.end());
    for(int to : ans)
        printf("%d ", to);
    return 0;
}

Compilation message

pastiri.cpp: In function 'int main()':
pastiri.cpp:63:9: error: 'active' was not declared in this scope; did you mean 'ctime'?
   63 |         active[y] = true;
      |         ^~~~~~
      |         ctime
pastiri.cpp:78:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   78 |     printf("%d\n", ans.size()); //ans.size() << "\n";
      |             ~^     ~~~~~~~~~~
      |              |             |
      |              int           std::vector<int>::size_type {aka long unsigned int}
      |             %ld
pastiri.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     scanf("%d%d",&n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~
pastiri.cpp:49:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         int u, v; scanf("%d%d", &u, &v);
      |                   ~~~~~^~~~~~~~~~~~~~~~
pastiri.cpp:61:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         int y; scanf("%d", &y);
      |                ~~~~~^~~~~~~~~~