답안 #859507

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859507 2023-10-10T09:11:41 Z Tenis0206 Newspapers (CEOI21_newspapers) C++11
12 / 100
1000 ms 9052 KB
#include <bits/stdc++.h>

using namespace std;

const int nmax = 20;

int n,m;

int G[nmax + 5];

int d[(1<<nmax) + 5];
pair<int,int> t[(1<<nmax) + 5];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifdef home
    freopen("nr.in","r",stdin);
    freopen("nr.out","w",stdout);
#endif // home
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        int x,y;
        cin>>x>>y;
        --x, --y;
        G[x] |= (1<<y);
        G[y] |= (1<<x);
    }
    if(m != n - 1)
    {
        cout<<"NO"<<'\n';
        return 0;
    }
    if(n > 20)
    {
        cout<<"YES"<<'\n';
        return 0;
    }
    queue<int> q;
    q.push((1<<n) - 1);
    d[(1<<n) - 1] = 1;
    t[(1<<n) - 1] = {-1,-1};
    while(!q.empty())
    {
        int mask = q.front();
        q.pop();
        for(int i=0; i<n; i++)
        {
            int new_mask = 0;
            for(int nod=0; nod<n; nod++)
            {
                if((mask & (1<<nod))!=0 && nod!=i)
                {
                    new_mask |= G[nod];
                }
            }
            if(!d[new_mask])
            {
                d[new_mask] = 1 + d[mask];
                t[new_mask] = {i,mask};
                q.push(new_mask);
            }
        }
    }
    if(!d[0])
    {
        cout<<"NO"<<'\n';
        return 0;
    }
    vector<int> rez;
    int mask = 0;
    while(mask != -1)
    {
        if(t[mask].first != -1)
        {
            rez.push_back(t[mask].first + 1);
        }
        mask = t[mask].second;
    }
    reverse(rez.begin(),rez.end());
    cout<<"YES"<<'\n';
    cout<<rez.size()<<'\n';
    for(auto it : rez)
    {
        cout<<it<<' ';
    }
    cout<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4696 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4700 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4700 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 1 ms 6492 KB Output is correct
53 Correct 1 ms 6492 KB Output is correct
54 Correct 1 ms 6492 KB Output is correct
55 Correct 1 ms 8796 KB Output is correct
56 Correct 1 ms 8540 KB Output is correct
57 Correct 2 ms 9052 KB Output is correct
58 Correct 1 ms 8796 KB Output is correct
59 Correct 0 ms 600 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 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 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Runtime error 1 ms 604 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4696 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4700 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4700 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 1 ms 6492 KB Output is correct
53 Correct 1 ms 6492 KB Output is correct
54 Correct 1 ms 6492 KB Output is correct
55 Correct 1 ms 8796 KB Output is correct
56 Correct 1 ms 8540 KB Output is correct
57 Correct 2 ms 9052 KB Output is correct
58 Correct 1 ms 8796 KB Output is correct
59 Correct 0 ms 600 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 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 2396 KB Output is correct
66 Correct 0 ms 2396 KB Output is correct
67 Correct 1 ms 2396 KB Output is correct
68 Correct 1 ms 2396 KB Output is correct
69 Correct 1 ms 2396 KB Output is correct
70 Correct 1 ms 2396 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 2396 KB Output is correct
73 Correct 1 ms 2396 KB Output is correct
74 Correct 0 ms 2396 KB Output is correct
75 Correct 0 ms 2396 KB Output is correct
76 Correct 0 ms 2396 KB Output is correct
77 Correct 0 ms 2396 KB Output is correct
78 Correct 1 ms 2396 KB Output is correct
79 Execution timed out 1093 ms 348 KB Time limit exceeded
80 Halted 0 ms 0 KB -