QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#716652 | #9525. Welcome to Join the Online Meeting! | zhensama | WA | 0ms | 3596kb | C++20 | 1.9kb | 2024-11-06 15:44:08 | 2024-11-06 15:44:13 |
Judging History
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();
}
詳細信息
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