Submission #531555

# Submission time Handle Problem Language Result Execution time Memory
531555 2022-03-01T04:03:07 Z eecs Newspapers (CEOI21_newspapers) C++17
4 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1010;
int n, m, d[maxn], pre[maxn];
vector<int> path, ans, G[maxn];

int main() {
    scanf("%d %d", &n, &m);
    if (m >= n) puts("NO"), exit(0);
    while (m--) {
        int u, v;
        scanf("%d %d", &u, &v);
        G[u].push_back(v), G[v].push_back(u);
    }
    auto bfs = [&]() {
        queue<int> Q;
        for (int i = 1; i <= n; i++) {
            if (!d[i]) Q.push(i);
        }
        while (!Q.empty()) {
            int u = Q.front(); Q.pop();
            for (int v : G[u]) if (!~d[v]) {
                Q.push(v), d[v] = d[u] + 1, pre[v] = u;
            }
        }
    };
    memset(d, -1, sizeof(d));
    d[1] = 0, bfs();
    int s = max_element(d + 1, d + n + 1) - d;
    memset(d, -1, sizeof(d));
    d[s] = 0, bfs();
    int t = max_element(d + 1, d + n + 1) - d;
    for (int i = t; i ^ s; i = pre[i]) path.push_back(i);
    path.push_back(s);
    memset(d, -1, sizeof(d));
    for (int i : path) d[i] = 0;
    bfs();
    if (*max_element(d + 1, d + n + 1) > 2) puts("NO"), exit(0);
    for (int i = 1; i + 1 < path.size(); i++) {
        ans.push_back(path[i]), ans.push_back(path[i]);
        for (int j : G[i]) if (d[j] == 1) {
            bool flag = 0;
            for (int k : G[j]) flag |= d[k] == 2;
            if (flag) ans.push_back(path[j]), ans.push_back(path[i]);
        }
    }
    if (ans.empty()) ans.push_back(1);
    printf("YES\n%d\n", ans.size());
    for (int x : ans) printf("%d ", x);
    return 0;
}

Compilation message

newspapers.cpp: In function 'int main()':
newspapers.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i = 1; i + 1 < path.size(); i++) {
      |                     ~~~~~~^~~~~~~~~~~~~
newspapers.cpp:49:19: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   49 |     printf("YES\n%d\n", ans.size());
      |                  ~^     ~~~~~~~~~~
      |                   |             |
      |                   int           std::vector<int>::size_type {aka long unsigned int}
      |                  %ld
newspapers.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
newspapers.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Partially correct 1 ms 308 KB Failed to provide a successful strategy.
3 Partially correct 0 ms 204 KB Failed to provide a successful strategy.
4 Partially correct 0 ms 320 KB Failed to provide a successful strategy.
5 Correct 1 ms 204 KB Output is correct
6 Partially correct 0 ms 316 KB Failed to provide a successful strategy.
7 Correct 0 ms 324 KB Output is correct
8 Incorrect 1 ms 204 KB Integer 0 violates the range [1, 7]
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Partially correct 0 ms 320 KB Failed to provide a successful strategy.
3 Correct 1 ms 204 KB Output is correct
4 Partially correct 0 ms 204 KB Failed to provide a successful strategy.
5 Partially correct 1 ms 204 KB Failed to provide a successful strategy.
6 Partially correct 1 ms 204 KB Failed to provide a successful strategy.
7 Partially correct 1 ms 204 KB Failed to provide a successful strategy.
8 Partially correct 1 ms 316 KB Failed to provide a successful strategy.
9 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
10 Partially correct 1 ms 204 KB Failed to provide a successful strategy.
11 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
12 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
13 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
14 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
15 Partially correct 1 ms 324 KB Failed to provide a successful strategy.
16 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
17 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
18 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
19 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
20 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Partially correct 1 ms 308 KB Failed to provide a successful strategy.
3 Partially correct 0 ms 204 KB Failed to provide a successful strategy.
4 Partially correct 0 ms 320 KB Failed to provide a successful strategy.
5 Correct 1 ms 204 KB Output is correct
6 Partially correct 0 ms 316 KB Failed to provide a successful strategy.
7 Correct 0 ms 324 KB Output is correct
8 Incorrect 1 ms 204 KB Integer 0 violates the range [1, 7]
9 Halted 0 ms 0 KB -