Submission #1089398

# Submission time Handle Problem Language Result Execution time Memory
1089398 2024-09-16T11:54:28 Z hihihah Pastiri (COI20_pastiri) C++14
0 / 100
254 ms 41124 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);

    #define orz "mo"
    if(fopen(orz".inp", "r")){
        freopen(orz".inp", "r", stdin);
        freopen(orz".out", "w", stdout);
    }

    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 << '\n' << c[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;
                    trc[i] = u; 
                    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:49:8: warning: unused variable 'res' [-Wunused-variable]
   49 |     ll res = 0;
      |        ^~~
pastiri.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(orz".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
pastiri.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen(orz".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 102 ms 34384 KB Output is correct
2 Incorrect 135 ms 40276 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 12380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 12120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 254 ms 41124 KB Output isn't correct
2 Halted 0 ms 0 KB -