QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#845408 | #9525. Welcome to Join the Online Meeting! | xiezheyuan | WA | 2ms | 9132kb | C++14 | 1.7kb | 2025-01-06 16:34:19 | 2025-01-06 16:34:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, M = 5e5 + 5;
int n, m, k, fa[N];
bool busy[N], called[N];
int find(int x){
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
vector<int> t[N];
void add(int x, int y){ t[x].push_back(y), t[y].push_back(x); }
vector<vector<int> > opts;
void dfs(int u, int fa){
t[u].erase(find(t[u].begin(), t[u].end(), fa));
if(t[u].empty()) return;
vector<int> vct = t[u];
vct.insert(vct.begin(), vct.size());
vct.insert(vct.begin(), u);
opts.push_back(vct);
for(int v : t[u]) dfs(v, u);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n >> m >> k;
for(int i=1,t;i<=k;i++) cin >> t, busy[t] = 1;
for(int i=1;i<=n;i++){
if(!busy[i]) called[i] = true;
}
iota(fa + 1, fa + n + 1, 1);
for(int i=1;i<=m;i++){
int u, v; cin >> u >> v;
if(!called[u] && !called[v]) continue;
if(!(busy[u] || busy[v])){
if(find(u) != find(v)) fa[find(u)] = find(v), add(u, v);
continue;
}
if(busy[u]){
if(!called[u]) add(u, v), called[u] = 1;
}
else{
if(!called[v]) add(u, v), called[v] = 1;
}
}
for(int i=1;i<=n;i++){
if(busy[i] && !called[i]) return (cout << "No\n"), 0;
}
cout << "Yes\n";
int rt = 0;
for(int i=1;i<=n;i++){
if(!busy[i]){ rt = i; break; }
}
t[rt].push_back(0);
dfs(rt, 0);
cout << opts.size() << '\n';
for(auto i : opts){
for(int j : i) cout << j << ' ';
cout << '\n';
}
return 0;
}
// Written by xiezheyuan
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 8796kb
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: 2ms
memory: 8188kb
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: 2ms
memory: 9132kb
input:
4 6 2 3 4 1 3 1 4 2 3 2 4 1 2 3 4
output:
Yes 1 1 3 3 4 2
result:
ok ok
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 8292kb
input:
6 6 0 1 2 2 3 3 1 4 5 5 6 6 4
output:
Yes 2 1 1 2 2 1 3
result:
wrong answer member 4 is not invited