Submission #1089397

# Submission time Handle Problem Language Result Execution time Memory
1089397 2024-09-16T11:46:15 Z hihihah Pastiri (COI20_pastiri) C++17
0 / 100
225 ms 34644 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define all(x) x.begin(), x.end();
using namespace std;
const int N = 1e9 + 7;

int n, k;
vector<int> ke[500009];
int c[500009];
int dd[500009];
int vis[500009];
int trc[500009];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin >> n >> k;
    for(int i = 1; i < n; i ++){
        int u, v;
        cin >> u >> v;
        ke[u].push_back(v);
        ke[v].push_back(u);
    }

    for(int i = 1; i <= k; i ++)
        cin >> c[i];

    if(k == 1){
        cout << 1;
        return 0;
    }

    queue<int> q;
    for(int i = 1; i <= k; i ++){
        q.push(c[i]);
        vis[c[i]] = 1;
        dd[c[i]] = 1;
        trc[c[i]] = c[i];
    }

    ll res = 0;

    while(q.size()){
        int u = q.front();
        q.pop();
        for(int i : ke[u])
            if(i != trc[u]){
                if(!dd[i]){
                    vis[i] = vis[u];
                    dd[i] = dd[u] + 1;
                    q.push(i);
                }
                else if(dd[i] == dd[u] + 1)
                        vis[i] += vis[u];
            }
    }

    vector<int> sav;

    for(int i = 1; i <= n; i ++)
    {
        if(ke[i].size() == 1 && vis[i] == 1) continue;
        int mx = 0;
        for(int j : ke[i])
            mx = max(mx, dd[j]);
        if(dd[i] >= mx) sav.push_back(i);
    }

    cout << sav.size() << '\n';
    for(int i : sav) cout << i << " ";
}

Compilation message

pastiri.cpp: In function 'int main()':
pastiri.cpp:43:8: warning: unused variable 'res' [-Wunused-variable]
   43 |     ll res = 0;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 27728 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 12376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 12124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 225 ms 34644 KB Output isn't correct
2 Halted 0 ms 0 KB -