Submission #785944

# Submission time Handle Problem Language Result Execution time Memory
785944 2023-07-17T19:54:00 Z Ozy Newspapers (CEOI21_newspapers) C++17
8 / 100
1 ms 480 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)

#define MAX 1000

lli a,b,m,n;
vector<lli> hijos[MAX+2];
vector<lli> res;
lli tam[MAX+2];

void pre_dfs(lli pos, lli padre) {

    tam[pos] = 1;
    for(auto h : hijos[pos]) {
        if (h == padre) continue;
        pre_dfs(h,pos);
        tam[pos] += tam[h];
    }
}

bool checa(lli pos, lli padre) {
    lli sig,may = 0;

    res.push_back(pos);

    for(auto h : hijos[pos]) {
        if(h == padre) continue;
        if (tam[h] > 1) {
            may++;
            sig = h;
        }
    }

    if (may > 1) return false;
    if (may == 0) return true;
    return checa(sig,pos);
}

bool sepuede(lli raiz) {

    res.clear();
    pre_dfs(raiz,0);
    return checa(raiz,0);
}

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

    cin >> n >> m;
    rep(i,1,m) {
        cin >> a >> b;
        hijos[a].push_back(b);
        hijos[b].push_back(a);
    }

    if (m >= n) {
        cout << "NO";
        return 0;
    }

    if (n == 1) {
        cout << "YES\n";
        cout << "1\n";
        cout << "1\n";
        return 0;
    }
    if (n == 2) {
        cout << "YES\n";
        cout << "2\n";
        cout << "1 1\n";
        return 0;
    }

    rep(i,1,n) {
        if (hijos[i].size() == 1 && sepuede(i)) {
            cout << "YES\n";
            cout << (res.size()*2-2) << "\n";
            for(auto r : res) if (r != i) cout << r << ' ';
            reverse(res.begin(), res.end());
            for(auto r : res) if (r != i) cout << r << ' ';
            return 0;
        }
    }

    cout << "NO";
    return 0;
}

Compilation message

newspapers.cpp: In function 'bool checa(long long int, long long int)':
newspapers.cpp:42:17: warning: 'sig' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |     return checa(sig,pos);
      |            ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 480 KB Output is correct
19 Correct 1 ms 356 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -