Submission #497187

# Submission time Handle Problem Language Result Execution time Memory
497187 2021-12-22T16:05:42 Z Victor Newspapers (CEOI21_newspapers) C++17
4 / 100
7 ms 416 KB
    // #pragma GCC target ("avx,avx2,fma")
    // #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
    // #pragma GCC optimize ("unroll-loops")
    #include <bits/stdc++.h>
     
    using namespace std;
     
    #define rep(i, a, b) for (int i = (a); i < (b); ++i)
    #define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
    #define trav(a, x) for (auto &a : x)
     
    #define all(x) x.begin(), x.end()
    #define sz(x) x.size()
    #define pb push_back
    #define debug(x) cout << #x << " = " << x << endl
     
    #define umap unordered_map
    #define uset unordered_set
     
    typedef pair<int, int> ii;
    typedef pair<int, ii> iii;
    typedef vector<int> vi;
    typedef vector<ii> vii;
    typedef vector<vi> vvi;
     
    typedef long long ll;
    typedef pair<ll, ll> pll;
    typedef vector<ll> vll;
    typedef vector<pll> vpll;
     
    const int INF = 1'000'000'007;
     
    int n, m;
    vi ans, graph[1001];
    int parity[1001], cnt[1001];
    bitset<1001> removed;
     
    void dfs(int u, int p, int c) {
        parity[u] = c;
        trav(v, graph[u]) if (v != p) dfs(v, u, c ^ 1);
    }
     
    int main() {
        cin.tie(0)->sync_with_stdio(0);
        cin.exceptions(cin.failbit);
     
        memset(parity, -1, sizeof(parity));
        cin >> n >> m;
        if(m>=n){
            cout<<"NO"<<endl;
            return 0;
        }
     
        rep(i, 0, m) {
            int u, v;
            cin >> u >> v;
            graph[--u].pb(--v);
            graph[v].pb(u);
        }
     
        dfs(0, 0, 0);
        bool moves = 0;
        while (1) {
            if (sz(ans) > 5 * n) break;
            int need = 0, node;
            bool stop=1;
            memset(cnt, 0, sizeof(cnt));
     
            rep(u, 0, n) if (moves == parity[u] && !removed[u]) {
                stop=0;
                bool adj_rem = 0;
                trav(v, graph[u]) {
                    ++cnt[v];
                    if (removed[v]) adj_rem = 1;
                }
                need += adj_rem;
                if (need) node = u;
            }
     
            if(stop)break;
     
            if (need > 1) {
                cout << "YES" << endl;
                return 0;
            }
     
            if (!need) {
                int mx_rem = -1;
                rep(u, 0, n) if (moves == parity[u] && !removed[u]) {
                    int cur_rem = 0;
                    trav(v, graph[u]) if (cnt[v] == 1)++ cur_rem;
                    if (cur_rem > mx_rem) {
                        mx_rem = cur_rem;
                        node = u;
                    }
                }
            }
     
            //cout<<"moves = "<<moves<<" node = "<<node<<endl;
            ans.pb(node);
            trav(v, graph[node])-- cnt[v];
            moves ^= 1;
            rep(u, 0, n) if (parity[u] == moves && !cnt[u]) removed[u] = 1;
        }
     
        if (sz(ans) > 5 * n)
            cout << "NO" << endl;
     
        else {
            cout << "YES\n"
                 << 2 * sz(ans) + 1 - moves<<endl;
            trav(pos,ans)cout<<pos+1<<' ';
            if(!moves)cout<<"1 ";
            trav(pos,ans)cout<<pos+1<<' ';
            cout<<endl;
        }
     
        return 0;
    }

Compilation message

newspapers.cpp: In function 'int main()':
newspapers.cpp:64:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |             if (sz(ans) > 5 * n) break;
      |                         ^
newspapers.cpp:106:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  106 |         if (sz(ans) > 5 * n)
      |                     ^
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 332 KB Provide a successful but not optimal strategy.
2 Correct 0 ms 332 KB Output is correct
3 Partially correct 1 ms 332 KB Provide a successful but not optimal strategy.
4 Partially correct 0 ms 332 KB Failed to provide a successful strategy.
5 Correct 0 ms 332 KB Output is correct
6 Partially correct 1 ms 332 KB Provide a successful but not optimal strategy.
7 Correct 0 ms 332 KB Output is correct
8 Partially correct 1 ms 344 KB Failed to provide a successful strategy.
9 Incorrect 0 ms 332 KB Unexpected end of file - int32 expected
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 332 KB Provide a successful but not optimal strategy.
2 Correct 0 ms 332 KB Output is correct
3 Partially correct 0 ms 332 KB Provide a successful but not optimal strategy.
4 Partially correct 0 ms 332 KB Provide a successful but not optimal strategy.
5 Partially correct 0 ms 332 KB Provide a successful but not optimal strategy.
6 Partially correct 0 ms 332 KB Failed to provide a successful strategy.
7 Partially correct 0 ms 332 KB Provide a successful but not optimal strategy.
8 Partially correct 0 ms 332 KB Failed to provide a successful strategy.
9 Partially correct 0 ms 332 KB Provide a successful but not optimal strategy.
10 Partially correct 0 ms 332 KB Failed to provide a successful strategy.
11 Partially correct 6 ms 416 KB Failed to provide a successful strategy.
12 Partially correct 2 ms 332 KB Provide a successful but not optimal strategy.
13 Partially correct 3 ms 332 KB Failed to provide a successful strategy.
14 Partially correct 4 ms 332 KB Failed to provide a successful strategy.
15 Partially correct 3 ms 332 KB Provide a successful but not optimal strategy.
16 Partially correct 7 ms 332 KB Failed to provide a successful strategy.
17 Partially correct 6 ms 332 KB Provide a successful but not optimal strategy.
18 Partially correct 6 ms 332 KB Failed to provide a successful strategy.
19 Partially correct 5 ms 332 KB Provide a successful but not optimal strategy.
20 Partially correct 7 ms 332 KB Failed to provide a successful strategy.
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 332 KB Provide a successful but not optimal strategy.
2 Correct 0 ms 332 KB Output is correct
3 Partially correct 1 ms 332 KB Provide a successful but not optimal strategy.
4 Partially correct 0 ms 332 KB Failed to provide a successful strategy.
5 Correct 0 ms 332 KB Output is correct
6 Partially correct 1 ms 332 KB Provide a successful but not optimal strategy.
7 Correct 0 ms 332 KB Output is correct
8 Partially correct 1 ms 344 KB Failed to provide a successful strategy.
9 Incorrect 0 ms 332 KB Unexpected end of file - int32 expected
10 Halted 0 ms 0 KB -