QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#884409#9525. Welcome to Join the Online Meeting!1903331632WA 2ms5868kbC++232.5kb2025-02-06 04:33:052025-02-06 04:33:06

Judging History

This is the latest submission verdict.

  • [2025-02-06 04:33:06]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 5868kb
  • [2025-02-06 04:33:05]
  • Submitted

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[i])
                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: 5732kb

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: -100
Wrong Answer
time: 0ms
memory: 5868kb

input:

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

output:

Yes
1
1 2 2 3 

result:

wrong answer member 4 is not invited