답안 #940699

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940699 2024-03-07T13:41:02 Z berr Newspapers (CEOI21_newspapers) C++17
54 / 100
119 ms 47512 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m; cin >> n >> m;

    vector<vector<int>> g(n);
    vector<int> d(n), val(n);

    for(int i=0; i<m; i++){
        int x, y; cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    int flag = 1;

    auto dfs=[&](int v, int p, auto&&dfs)->int{
        if(v==p) d[v]=0;
        else d[v]=d[p]+1;

        val[v] = d[v];

        vector<int> a;
        for(auto i: g[v]){  
            if(i!=p) a.push_back(dfs(i, v, dfs));
        }

        sort(a.begin(), a.end());
        sort(g[v].begin(), g[v].end(), [&](int x, int y){
            return val[x]<val[y];
        });

        if(a.size())
        val[v]=max(val[v], a.back());

        if(v==p){
            if(a.size()>2 && a[a.size()-3] >2) flag =0;
        }
        return val[v];
          
    };

    if(n==m+1)
    for(int i=0; i<n; i++) dfs(i, i, dfs);
    else flag =0;

    if(flag){ 
        cout<<"YES\n";
        if(n==1) cout<<1<<" "<<1<<"\n";
        else if(n==2) cout<<"2 2 2"<<"\n";
        else{
            
            vector a(n, vector(n, vector<int>()));
            vector vis(n, vector(n, 0));

            auto dfs2=[&](int v, int p, auto&&dfs2)->vector<int>{
                vector<int> s; 
                if(vis[v][p]) return a[v][p];
                vis[v][p]=1;
             //   cout<<v<<" "<<d[v]<<" "<<val[v]<<"\n";
                if(d[v]==val[v]) return a[v][p]=s;
                else if(d[v]==val[v]-1){
                    s.push_back(v);
                    return a[v][p]=s;
                }            
                else{
                    vector<int> b;
                    vector<vector<int>> c;

                    for(auto i: g[v]){
                        if(i==p) continue;

                        c.push_back(dfs2(i, v, dfs2));
                    }

                 
                    if(!c.back().size()){
                        return b;
                    }

                  /*  cout<<v+1<<"\n";
                    for(auto i: c){
                        for(auto l: i) cout<<l+1<<" ";
                            cout<<"\n";
                    }*/

                    for(auto i: c.back()) b.push_back(i);
                    b.push_back(v);

                    for(int i=0; i<c.size()-1; i++){
                        if(!c[i].size()){
                            continue;
                        }
                        for(auto j: c[i]){
                            b.push_back(j);
                        }
                        b.push_back(v);


                    }
                    

                    return a[v][p]=b;
                }
            };

            vector<int> x;

            for(int i=0; i<n; i++){
                dfs(i, i, dfs);
                auto s = dfs2(i, i, dfs2);

                if(!x.size()) x = s;
                else if(s.size()<x.size()) x = s; 
            }

           // reverse(x.begin(), x.end());

            for(int i=x.size()-1; i>=0; i--){
                x.push_back(x[i]);
            }

            cout<<x.size()<<"\n";

            for(auto i: x) cout<<i+1<<" ";
                cout<<"\n";


        } 
    }
    else cout<<"NO\n";

}

Compilation message

newspapers.cpp: In lambda function:
newspapers.cpp:95:35: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |                     for(int i=0; i<c.size()-1; i++){
      |                                  ~^~~~~~~~~~~
newspapers.cpp: In instantiation of 'main()::<lambda(long long int, long long int, auto:24&&)> [with auto:24 = main()::<lambda(long long int, long long int, auto:24&&)>&]':
newspapers.cpp:116:41:   required from here
newspapers.cpp:95:35: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
# 결과 실행 시간 메모리 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 1 ms 708 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Partially correct 1 ms 348 KB Failed to provide a successful strategy.
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Partially correct 0 ms 348 KB Failed to provide a successful strategy.
39 Partially correct 1 ms 456 KB Failed to provide a successful strategy.
40 Partially correct 0 ms 348 KB Failed to provide a successful strategy.
41 Partially correct 1 ms 348 KB Failed to provide a successful strategy.
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Partially correct 0 ms 348 KB Failed to provide a successful strategy.
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 460 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Partially correct 1 ms 348 KB Failed to provide a successful strategy.
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 91 ms 42384 KB Output is correct
12 Correct 27 ms 12512 KB Output is correct
13 Correct 37 ms 17492 KB Output is correct
14 Correct 48 ms 19288 KB Output is correct
15 Correct 46 ms 21844 KB Output is correct
16 Correct 98 ms 46932 KB Output is correct
17 Correct 97 ms 47180 KB Output is correct
18 Correct 100 ms 47372 KB Output is correct
19 Correct 99 ms 47220 KB Output is correct
20 Correct 104 ms 47376 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 708 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Partially correct 1 ms 348 KB Failed to provide a successful strategy.
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Partially correct 0 ms 348 KB Failed to provide a successful strategy.
39 Partially correct 1 ms 456 KB Failed to provide a successful strategy.
40 Partially correct 0 ms 348 KB Failed to provide a successful strategy.
41 Partially correct 1 ms 348 KB Failed to provide a successful strategy.
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Partially correct 0 ms 348 KB Failed to provide a successful strategy.
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 460 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Partially correct 1 ms 348 KB Failed to provide a successful strategy.
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 1 ms 352 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 1 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 456 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 29 ms 532 KB Output is correct
80 Correct 30 ms 524 KB Output is correct
81 Correct 38 ms 348 KB Output is correct
82 Correct 36 ms 348 KB Output is correct
83 Correct 34 ms 348 KB Output is correct
84 Correct 30 ms 344 KB Output is correct
85 Correct 31 ms 348 KB Output is correct
86 Correct 31 ms 536 KB Output is correct
87 Correct 33 ms 344 KB Output is correct
88 Correct 27 ms 520 KB Output is correct
89 Correct 117 ms 40212 KB Output is correct
90 Partially correct 90 ms 31316 KB Failed to provide a successful strategy.
91 Correct 83 ms 29520 KB Output is correct
92 Correct 73 ms 25172 KB Output is correct
93 Partially correct 114 ms 39240 KB Failed to provide a successful strategy.
94 Partially correct 79 ms 27476 KB Failed to provide a successful strategy.
95 Partially correct 118 ms 42076 KB Failed to provide a successful strategy.
96 Partially correct 116 ms 40524 KB Failed to provide a successful strategy.
97 Partially correct 69 ms 24144 KB Failed to provide a successful strategy.
98 Partially correct 113 ms 39244 KB Failed to provide a successful strategy.
99 Partially correct 84 ms 30032 KB Failed to provide a successful strategy.
100 Partially correct 98 ms 32060 KB Failed to provide a successful strategy.
101 Correct 84 ms 29264 KB Output is correct
102 Partially correct 83 ms 30148 KB Failed to provide a successful strategy.
103 Partially correct 95 ms 32532 KB Failed to provide a successful strategy.
104 Partially correct 68 ms 23636 KB Failed to provide a successful strategy.
105 Correct 74 ms 26448 KB Output is correct
106 Correct 113 ms 34896 KB Output is correct
107 Partially correct 87 ms 27220 KB Failed to provide a successful strategy.
108 Correct 119 ms 40032 KB Output is correct
109 Correct 93 ms 31824 KB Output is correct
110 Partially correct 108 ms 31576 KB Failed to provide a successful strategy.
111 Correct 76 ms 26448 KB Output is correct
112 Partially correct 79 ms 27984 KB Failed to provide a successful strategy.
113 Partially correct 116 ms 40964 KB Failed to provide a successful strategy.
114 Partially correct 97 ms 34640 KB Failed to provide a successful strategy.
115 Correct 83 ms 28496 KB Output is correct
116 Correct 95 ms 33108 KB Output is correct
117 Correct 116 ms 42044 KB Output is correct
118 Partially correct 99 ms 34628 KB Failed to provide a successful strategy.
119 Correct 89 ms 30060 KB Output is correct
120 Partially correct 104 ms 36432 KB Failed to provide a successful strategy.
121 Correct 104 ms 36436 KB Output is correct
122 Correct 83 ms 28732 KB Output is correct
123 Partially correct 78 ms 26448 KB Failed to provide a successful strategy.
124 Partially correct 115 ms 39764 KB Failed to provide a successful strategy.
125 Correct 69 ms 23968 KB Output is correct
126 Partially correct 75 ms 26332 KB Failed to provide a successful strategy.
127 Partially correct 75 ms 25184 KB Failed to provide a successful strategy.
128 Partially correct 111 ms 39508 KB Failed to provide a successful strategy.
129 Correct 43 ms 348 KB Output is correct
130 Correct 42 ms 520 KB Output is correct
131 Correct 42 ms 348 KB Output is correct
132 Correct 41 ms 512 KB Output is correct
133 Correct 47 ms 596 KB Output is correct
134 Correct 11 ms 2908 KB Output is correct
135 Correct 9 ms 3160 KB Output is correct
136 Correct 25 ms 9052 KB Output is correct
137 Correct 16 ms 5212 KB Output is correct
138 Correct 26 ms 7248 KB Output is correct
139 Correct 50 ms 12024 KB Output is correct
140 Correct 7 ms 2136 KB Output is correct
141 Correct 3 ms 1112 KB Output is correct
142 Correct 45 ms 12292 KB Output is correct
143 Correct 54 ms 12328 KB Output is correct
144 Correct 101 ms 47300 KB Output is correct
145 Correct 99 ms 47512 KB Output is correct