Submission #977558

# Submission time Handle Problem Language Result Execution time Memory
977558 2024-05-08T06:55:08 Z Circling Newspapers (CEOI21_newspapers) C++17
8 / 100
2 ms 504 KB
/*The British Royal Family and a small cadre of English Fabian Socialists, in
conjunction with the Rockefellers and the Rothchilds, are engaged in a
conspiracy to greatly reduce the population of the human race in order to head
off a Malthusian catastrophe, a catastrophe that could easily be avoided by
simply building a massive amount of nuclear power plants and a number of massive
superhighways and bridges to connect all of the world's continents. But doing
that would cut into the conspiracy's profits. So the British Royal Family
invented environmentalism and neoliberalism in order to hide the truth. And in
order to further reduce the population, the British Royal Family is also the
world's foremost drug trafficking conspiracy. And it uses its control of the IMF
to push austerity in order to kill as many people in the global south as
possible.
And also Henry Kissinger is a gay KGB agent. */
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;


int main(){
    int n, m, u, v, nlc, last, last2;
    cin >> n >> m;
    if (m != n - 1){
        cout << "NO";
        return 0;
    }
    if (n == 1){
        cout << "YES\n1\n1";
        return 0;
    }
    if (n == 2){
        cout << "YES\n2\n1 1";
        return 0;
    }
    vector<vector<int>> graph;
    graph.resize(n + 1);
    while (m--){
        cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    for (int i = 1; i <= n; i++){
        nlc = 0;
        for (int j: graph[i]) if (graph[j].size() > 1) nlc++;
        if (nlc > 2){
            cout << "NO";
            return 0;
        }
    }
    vector<bool> seen;
    for (int i = 0; i <= n; i++) seen.push_back(false);
    queue<int> q;
    q.push(1);
    while (!q.empty()){
        last = q.front();
        q.pop();
        seen[last] = true;
        for (int i: graph[last]) if (!seen[i]) q.push(i);
    }
    vector<int> prev, diameter;
    for (int i = 0; i <= n; i++) prev.push_back(0);
    q.push(last);
    while (!q.empty()){
        last2 = q.front();
        q.pop();
        for (int i: graph[last2]){
            if (i != prev[last2]){
                prev[i] = last2;
                q.push(i);
            }
        }
    }
    for (int i = last2; i != last; i = prev[i]) diameter.push_back(i);
    cout << "YES\n" << 2 * diameter.size() - 2 << '\n';
    for (int i = 1; i < diameter.size(); i++) cout << diameter[i] << ' ';
    for (int i = diameter.size() - 1; i > 0; i--) cout << diameter[i] << ' ';
}

Compilation message

newspapers.cpp: In function 'int main()':
newspapers.cpp:80:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for (int i = 1; i < diameter.size(); i++) cout << diameter[i] << ' ';
      |                     ~~^~~~~~~~~~~~~~~~~
newspapers.cpp:78:27: warning: 'last2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   78 |     for (int i = last2; i != last; i = prev[i]) diameter.push_back(i);
      |                         ~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 1 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 500 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 440 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 1 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -