QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#716652#9525. Welcome to Join the Online Meeting!zhensamaWA 0ms3596kbC++201.9kb2024-11-06 15:44:082024-11-06 15:44:13

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 15:44:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3596kb
  • [2024-11-06 15:44:08]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
using namespace std;
void solve()
{
    int n,m,k;cin>>n>>m>>k;
    vector<int> G[n+1],sz[n+1],to[n+1];
    int out[n+1]={0},vis[n+1]={0},pos[n+1]={0};
    map<int,int> mp;
    for(int i=1;i<=k;i++)
    {
        int x; cin>>x;
        mp[x]=1;
    }
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        if(!mp[u])
        {
            G[u].push_back(v);
            out[u]++;
        }
        if(!mp[v])
        {
            G[v].push_back(u);
            out[v]++;
        }
    }
    int st=0;
    for(int i=1;i<=n;i++)
    {
        if(out[i])
        {
            st=i;
            break;
        }
    }
    queue<int> q;
    q.push(st);
    vis[st]=1;
    pos[st]=1;
    to[0].push_back(st);
    sz[1].push_back(st);
    int cnt=1;
    while(!q.empty())
    {
        int t=q.front();
        q.pop();
        cnt=pos[t]+1;
        for(auto v:G[t])
        {
            if(vis[v]) continue;
            vis[v]=1;
            to[t].push_back(v);
            pos[v]=pos[t]+1;
            sz[pos[v]].push_back(v);
            if(mp[v]) continue;
            q.push(v);
        }
    }
    int sum=0;
    for(int i=1;i<=n;i++)
        sum+=vis[i];
    if(sum<n)
    {
        cout<<"No\n";
        return;
    }
    else
    {
        cout<<"Yes\n";
        cout<<cnt-1<<'\n';
        for(int i=1;i<cnt;i++)
        {
            for(auto j:sz[i])
            {
                if(to[j].size())
                {
                    cout<<j<<" ";
                    cout<<to[j].size()<<" ";
                }
                for (auto k:to[j])
                    cout<<k<<" ";
            }

            cout<<'\n';
        }
    }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t=1;//cin>>t;
    while(t--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

input:

4 5 2
3 4
1 2
1 3
2 3
3 4
2 4

output:

Yes
2
1 2 2 3 
2 1 4 

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

4 5 3
2 4 3
1 2
1 3
2 3
3 4
2 4

output:

No

result:

ok ok

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3568kb

input:

4 6 2
3 4
1 3
1 4
2 3
2 4
1 2
3 4

output:

Yes
2
1 3 3 4 2 


result:

wrong output format Unexpected end of file - int32 expected