QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#884411 | #9525. Welcome to Join the Online Meeting! | 1903331632 | WA | 2ms | 5856kb | C++23 | 2.5kb | 2025-02-06 04:38:18 | 2025-02-06 04:38:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
#define pii pair<int, int>
#define lowbit(x) (x & (-x))
const int mod = 1e9 + 7;
int n, m, k;
bool st[N];
bool vis[N];
vector<int> e[N];
void solve()
{
cin >> n >> m >> k;
for (int i = 0; i < k; i++)
{
int x;
cin >> x;
st[x] = 1;
}
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
e[a].push_back(b);
e[b].push_back(a);
}
for (int i = 1; i <= n; i++)
{
if (st[i])
continue;
queue<int> q;
q.push(i);
vis[i] = 1;
while (!q.empty())
{
int u = q.front();
q.pop();
if (!st[u])
for (auto v : e[u])
{
if (vis[v])
continue;
q.push(v);
vis[v] = 1;
}
}
}
for (int i = 1; i <= n; i++)
{
if (vis[i] == 0)
{
cout << "No" << endl;
return;
}
}
vector<vector<int>> res;
for (int i = 1; i <= n; i++)
{
if (st[i] == 0)
{
cout << "Yes" << endl;
for (int j = 1; j <= n; j++)
vis[j] = 0;
queue<int> q;
q.push(i);
vis[i] = 1;
while (!q.empty())
{
int t = q.front();
q.pop();
vector<int> v;
if (st[t] == 0)
v.push_back(t);
for (int u : e[t])
{
if (vis[u])
continue;
if (v.size())
v.push_back(u);
q.push(u);
vis[u] = 1;
}
if (v.size() >= 2)
res.push_back(v);
}
cout << res.size() << endl;
for (auto t : res)
{
cout << t[0] << ' ' << t.size() - 1 << ' ';
for (int k = 1; k < t.size(); k++)
cout << t[k] << " ";
cout << endl;
}
return;
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 5736kb
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: 1ms
memory: 5856kb
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: 5740kb
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: 2ms
memory: 3712kb
input:
6 6 0 1 2 2 3 3 1 4 5 5 6 6 4
output:
Yes 1 1 2 2 3
result:
wrong answer member 4 is not invited