QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#720780#9525. Welcome to Join the Online Meeting!zzfs#WA 0ms3808kbC++141.9kb2024-11-07 14:04:572024-11-07 14:04:57

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 14:04:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3808kb
  • [2024-11-07 14:04:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve()
{
    int n, m, k;
    cin >> n >> m >> k;

    vector<int> vis(n + 1, 0);
    for (int i = 1; i <= k; i++)
    {
        int x;
        cin >> x;
        vis[x] = -1;
    }

    vector<vector<int>> g(n + 1);

    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int cnt = 0;

    vector<pair<int, vector<int>>> ans;

    auto bfs = [&](int s)
    {
        queue<int> q;
        q.push(s);
        vis[s] = 1;
        cnt++;

        while (!q.empty())
        {
            int u = q.front();
            q.pop();

            vector<int> tmp;
            for (auto v : g[u])
            {
                if (vis[v] == -1)
                {
                    vis[v] = 1;
                    cnt++;
                    tmp.push_back(v);
                }

                if (vis[v] == 0)
                {
                    vis[v] = 1;
                    cnt++;
                    tmp.push_back(v);
                    q.push(v);
                }
            }

            ans.push_back({u, tmp});
        }
    };

    for (int i = 1; i <= n; i++)
    {
        if (vis[i] == 0)
        {
            bfs(i);
            break;
        }
    }

    if (cnt != n)
    {
        cout << "No" << '\n';
        return;
    }

    cout << "Yes" << '\n';
    cout << ans.size() << '\n';
    for (auto [x, v] : ans)
    {
        if (v.size() == 0)
            continue;
        cout << x << ' ' << v.size();
        for (auto y : v)
            cout << ' ' << y;
        cout << '\n';
    }
}

signed main()
{
    cin.tie(0)->ios::sync_with_stdio(false);

    int t = 1;
    // cin >> t;
    while (t--)
        solve();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3808kb

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: 3808kb

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: 3492kb

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