QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#785416 | #9525. Welcome to Join the Online Meeting! | SZH# | WA | 59ms | 33880kb | C++14 | 2.4kb | 2024-11-26 17:53:46 | 2024-11-26 17:53:47 |
Judging History
answer
#include<bits/stdc++.h>
#define pa pair<int,int>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pb push_back
using namespace std;
inline ll read()
{
ll f=1,sum=0;char c=getchar();
while (!isdigit(c)) {if (c=='-') f=-1;c=getchar();}
while (isdigit(c)) {sum=sum*10+c-'0';c=getchar();}
return sum*f;
}
const int MAXN=200100;
const int MAXM=500010;
struct edge{
int next,to;
}e[MAXM*2];
int head[MAXN],cnt;
void addedge(int u,int v){
e[++cnt].next=head[u];
e[cnt].to=v;
head[u]=cnt;
}
int fa[MAXN];
int find(int x){
if (fa[x]!=x) fa[x]=find(fa[x]);
return fa[x];
}
int busy[MAXN];
pa es[MAXM];
vector <int> g[MAXN],gr[MAXN];
int vis[MAXN],ind[MAXN];
void dfs(int x)
{
vis[x]=1;
for (auto v:gr[x]) dfs(v);
}
vector <int> ans[MAXN];
int main()
{
int n=read(),m=read(),k=read();
for (int i=1;i<=k;i++)
{
int x=read();
busy[x]=1;
}
for (int i=1;i<=n;i++) fa[i]=i;
for (int i=1;i<=m;i++)
{
int u=read(),v=read();
es[i]=mp(u,v);
if (!busy[u] && !busy[v])
{
int f1=find(u),f2=find(v);
if (f1!=f2) fa[f1]=f2;
}
if (!busy[u]) addedge(u,v);
if (!busy[v]) addedge(v,u);
}
for (int i=1;i<=m;i++)
{
if (!busy[es[i].fi] && !busy[es[i].se]) continue;
if (!busy[es[i].fi])
{
int u=find(es[i].fi);
int v=find(es[i].se);
ind[v]++;
g[u].push_back(v);
gr[v].push_back(u);
}
if (!busy[es[i].se])
{
int u=find(es[i].se);
int v=find(es[i].fi);
ind[v]++;
g[u].push_back(v);
gr[v].push_back(u);
}
}
int x=0;
for (int i=1;i<=n && !x;i++)
{
if(!ind[i] && !busy[i]) x=i;
}
if (!x)
{
cout<<"No\n";
return 0;
}
memset(vis,0,sizeof(vis));
queue <int> q;
q.push(x);
vis[x]=1;
while (!q.empty())
{
int u=q.front();
q.pop();
for (int i=head[u];i;i=e[i].next)
{
int v=e[i].to;
if (vis[v]) continue;
ans[u].push_back(v);
vis[v]=1;
q.push(v);
}
}
bool flag=true;
for (int i=1;i<=n;i++) flag&=vis[find(i)];
if (!flag)
{
cout<<"No\n";
return 0;
}
cout<<"Yes\n";
vector <int> need_print;
for (int i=1;i<=n;i++) if (ans[i].size()) need_print.push_back(i);
cout<<need_print.size()<<'\n';
for (auto id:need_print)
{
cout<<id<<' '<<ans[id].size()<<' ';
for (auto v:ans[id]) cout<<v<<' ';
cout<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 22520kb
input:
4 5 2 3 4 1 2 1 3 2 3 3 4 2 4
output:
Yes 2 1 2 3 2 2 1 4
result:
ok ok
Test #2:
score: 0
Accepted
time: 5ms
memory: 18824kb
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: 0
Accepted
time: 0ms
memory: 18660kb
input:
4 6 2 3 4 1 3 1 4 2 3 2 4 1 2 3 4
output:
Yes 1 1 3 2 4 3
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 18468kb
input:
6 6 0 1 2 2 3 3 1 4 5 5 6 6 4
output:
No
result:
ok ok
Test #5:
score: -100
Wrong Answer
time: 59ms
memory: 33880kb
input:
200000 199999 2 142330 49798 49798 116486 116486 64386 64386 192793 192793 61212 61212 138489 138489 83788 83788 89573 89573 8596 8596 156548 156548 41800 41800 14478 14478 27908 27908 82806 82806 9353 9353 160166 160166 92308 92308 36265 36265 126943 126943 190578 190578 191148 191148 177381 177381...
output:
Yes 199998 1 2 178679 95113 2 1 198122 3 1 41738 4 1 196324 5 1 91673 6 1 796 7 1 136018 8 1 100182 9 1 101606 10 1 73864 11 1 105951 12 1 63827 13 1 130553 14 1 177897 15 1 196567 16 1 92389 17 1 72182 18 1 141202 19 1 45379 20 1 114057 21 1 105287 22 1 7260 23 1 40268 24 1 5...
result:
wrong answer on step #2, member 2 is not invited before inviting others