Submission #859512

# Submission time Handle Problem Language Result Execution time Memory
859512 2023-10-10T09:14:20 Z Tenis0206 Newspapers (CEOI21_newspapers) C++11
0 / 100
1 ms 2548 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;
    }
    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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2548 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -