Submission #602885

# Submission time Handle Problem Language Result Execution time Memory
602885 2022-07-23T12:18:38 Z cadmiumsky Newspapers (CEOI21_newspapers) C++14
75 / 100
192 ms 8120 KB
#include <bits/stdc++.h>

using namespace std;
using tii = tuple<int,int,int>;
const int nmax = 1e3 + 5;
vector<int> g[nmax], light[nmax];
int h[nmax], atrleaf[nmax], heavy[nmax];
int ondiam[nmax];

void chmax(tii &l, tii r) {
  l = max(l, r);
}

tii finddiam(int node, int f) {
  tii rez = {1, node, node};
  atrleaf[node] = node;
  h[node] = 1;
  for(auto x : g[node]) {
    if(x == f) continue;
    chmax(rez, finddiam(x, node));
    if(h[x] + 1 > h[node]) {
      h[node] = h[x] + 1;
      atrleaf[node] = atrleaf[x];
    }
  }
  int other = 0, atr = node;
  for(auto x : g[node]) {
    if(x == f || atrleaf[node] == atrleaf[x])
      continue;
    if(h[x] > other) {
      other = h[x];
      atr = atrleaf[x];
    }
  }
  chmax(rez, tii{other + h[node], atrleaf[node], atr});
  return rez;
  
}
static bool markdiam(int node, int f, int rez) {
  if(node == rez) {
    heavy[node] = -1;
    return 1;
  }
  ondiam[node] = 1;
  for(auto x : g[node]) {
    if(x == f)
      continue;
    if(markdiam(x, node, rez)) {
      heavy[node] = x;
      return 1;
    }
  }
  ondiam[node] = 0;
  return 0;
}
vector<int> rez;
  int len, l, r;
void commence(int node, bool state = 0) {
  if(heavy[node] == -1)
    return;
  if(state == 0) {
    commence(heavy[node], 0);
    rez.push_back(node);
    for(auto x : light[node])
      rez.push_back(x),
      rez.push_back(node);
    if(node != l)
      return;
    commence(node, 1);
    return;
  }
  if(state == 1) {
    rez.push_back(node);
    for(auto x : light[node])
      rez.push_back(x),
      rez.push_back(node);
    commence(heavy[node], 1);
    return;
  }
  
}

int main() {  
  int n, m;
  cin >> n >> m;
  if(n == 1) {
    cout << "YES\n1\n1\n";
    return 0;
  }
  for(int i = 0, x, y; i < m; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  if(m >= n) {
    cout << "NO\n";
    return 0;
  }
  tie(len, l, r) = finddiam(1, 1); 
  markdiam(l, l, r);
  finddiam(l, l);
  for(int i = 1; i <= n; i++) {
    if(ondiam[i] == 1) {
      for(auto x : g[i]) {
        if(ondiam[x])
          continue;
        if(h[x] > 2) {
          cout << "NO\n";
          return 0;
        }
        if(h[x] == 2)
          light[i].push_back(x);
      }
    }
  }
  commence(l);
  //cerr << l << ' ' << r<< '\n';
  cout << "YES\n" << rez.size() << '\n';
  for(auto x : rez)
    cout << x<< ' ';
  cout << '\n';
}
//4 1 6 1 2 3 3 2 1 6 1 4 
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
4 Partially correct 0 ms 348 KB Provide a successful but not optimal strategy.
5 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
6 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
7 Correct 0 ms 340 KB Output is correct
8 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
9 Correct 1 ms 340 KB Output is correct
10 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
11 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
12 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
13 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
14 Partially correct 0 ms 348 KB Provide a successful but not optimal strategy.
15 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
16 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
17 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
18 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
19 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
20 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
21 Partially correct 0 ms 352 KB Provide a successful but not optimal strategy.
22 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
23 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
24 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
25 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
26 Partially correct 0 ms 352 KB Provide a successful but not optimal strategy.
27 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
28 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
29 Correct 0 ms 340 KB Output is correct
30 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
31 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
32 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
33 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
34 Correct 0 ms 340 KB Output is correct
35 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
36 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
37 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
38 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
39 Partially correct 0 ms 352 KB Provide a successful but not optimal strategy.
40 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
41 Partially correct 1 ms 348 KB Provide a successful but not optimal strategy.
42 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
43 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
44 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
49 Correct 1 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Partially correct 1 ms 352 KB Provide a successful but not optimal strategy.
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
55 Correct 0 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 0 ms 340 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 0 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 0 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
4 Partially correct 0 ms 356 KB Provide a successful but not optimal strategy.
5 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
6 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
7 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
8 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
9 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
10 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
11 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
12 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
13 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
14 Partially correct 1 ms 480 KB Provide a successful but not optimal strategy.
15 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
16 Partially correct 2 ms 468 KB Provide a successful but not optimal strategy.
17 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
18 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
19 Partially correct 2 ms 468 KB Provide a successful but not optimal strategy.
20 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
4 Partially correct 0 ms 348 KB Provide a successful but not optimal strategy.
5 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
6 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
7 Correct 0 ms 340 KB Output is correct
8 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
9 Correct 1 ms 340 KB Output is correct
10 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
11 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
12 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
13 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
14 Partially correct 0 ms 348 KB Provide a successful but not optimal strategy.
15 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
16 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
17 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
18 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
19 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
20 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
21 Partially correct 0 ms 352 KB Provide a successful but not optimal strategy.
22 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
23 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
24 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
25 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
26 Partially correct 0 ms 352 KB Provide a successful but not optimal strategy.
27 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
28 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
29 Correct 0 ms 340 KB Output is correct
30 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
31 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
32 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
33 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
34 Correct 0 ms 340 KB Output is correct
35 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
36 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
37 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
38 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
39 Partially correct 0 ms 352 KB Provide a successful but not optimal strategy.
40 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
41 Partially correct 1 ms 348 KB Provide a successful but not optimal strategy.
42 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
43 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
44 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
49 Correct 1 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Partially correct 1 ms 352 KB Provide a successful but not optimal strategy.
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
55 Correct 0 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 0 ms 340 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 0 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 0 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 1 ms 296 KB Output is correct
67 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
68 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
69 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
70 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
71 Correct 0 ms 352 KB Output is correct
72 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
73 Correct 1 ms 348 KB Output is correct
74 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
75 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
76 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
77 Partially correct 1 ms 340 KB Provide a successful but not optimal strategy.
78 Partially correct 0 ms 340 KB Provide a successful but not optimal strategy.
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 352 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 1 ms 348 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 1 ms 340 KB Output is correct
88 Correct 1 ms 340 KB Output is correct
89 Partially correct 2 ms 488 KB Provide a successful but not optimal strategy.
90 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
91 Partially correct 1 ms 352 KB Provide a successful but not optimal strategy.
92 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
93 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
94 Partially correct 1 ms 352 KB Provide a successful but not optimal strategy.
95 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
96 Partially correct 1 ms 488 KB Provide a successful but not optimal strategy.
97 Partially correct 1 ms 352 KB Provide a successful but not optimal strategy.
98 Partially correct 2 ms 468 KB Provide a successful but not optimal strategy.
99 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
100 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
101 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
102 Partially correct 2 ms 468 KB Provide a successful but not optimal strategy.
103 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
104 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
105 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
106 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
107 Partially correct 1 ms 356 KB Provide a successful but not optimal strategy.
108 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
109 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
110 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
111 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
112 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
113 Partially correct 1 ms 480 KB Provide a successful but not optimal strategy.
114 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
115 Partially correct 1 ms 352 KB Provide a successful but not optimal strategy.
116 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
117 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
118 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
119 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
120 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
121 Partially correct 1 ms 484 KB Provide a successful but not optimal strategy.
122 Partially correct 1 ms 356 KB Provide a successful but not optimal strategy.
123 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
124 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
125 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
126 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
127 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
128 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
129 Correct 1 ms 340 KB Output is correct
130 Correct 1 ms 340 KB Output is correct
131 Correct 1 ms 340 KB Output is correct
132 Correct 1 ms 340 KB Output is correct
133 Correct 1 ms 352 KB Output is correct
134 Correct 38 ms 1968 KB Output is correct
135 Correct 32 ms 1976 KB Output is correct
136 Correct 94 ms 5456 KB Output is correct
137 Correct 56 ms 3404 KB Output is correct
138 Correct 102 ms 4700 KB Output is correct
139 Correct 177 ms 7920 KB Output is correct
140 Correct 25 ms 1484 KB Output is correct
141 Correct 10 ms 748 KB Output is correct
142 Correct 168 ms 7488 KB Output is correct
143 Correct 192 ms 8120 KB Output is correct
144 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.
145 Partially correct 1 ms 468 KB Provide a successful but not optimal strategy.