QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#735585#9525. Welcome to Join the Online Meeting!Foedere0Compile Error//C++203.0kb2024-11-11 20:49:552024-11-11 20:49:56

Judging History

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

  • [2024-11-11 20:49:56]
  • 评测
  • [2024-11-11 20:49:55]
  • 提交

answer

#include <bits/stdc++.h>
// #define endl '\n'
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 1000010;
int p[N], sz[N];
int a[N];
unordered_map<int, int> st;
int find(int x)
{
    if (p[x] != x)
        p[x] = find(p[x]);
    return p[x];
}
vector<int> ans[N];
void solve()
{
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
    {
        p[i] = i;
        sz[i] = 1;
        // ans[i].push_back(i);
    }
    for (int i = 1; i <= k; i++)
    {
        cin >> a[i];
        st[a[i]] = 1;
    }
    vector<PII> op;
    while (m--)
    {
        int x, y;
        cin >> x >> y;
        if (st[x] == 1 && !st[y])
        {
            st[x] = 2;
            ans[y].push_back(x);
            sz[y]++;
        }
        if (st[y] == 1 && !st[x])
        {
            st[y] = 2;
            ans[x].push_back(y);
            sz[x]++;
        }
        if (!st[y] && !st[x])
        {
            op.push_back({x, y});
        }
    }
    int x = 0;
    for (int i = 1; i <= n; i++)
    {
        if (!st[i])
        {
            x = i;
            break;
        }
    }
    if (x == 0)
    {
        cout << "No" << endl;
        return;
    }
    int cnt = 0;
    // sort(op.begin(), op.end());
    int t = x;
    for (auto [x, y] : op)
    {
        if (sz[find(x)] < sz[find(y)])
        {
            swap(x, y);
        }
        if (find(y) != find(x))
        {
            t = find(x);
            ans[x].push_back(y);
            sz[find(x)] += sz[find(y)];
            p[find(y)] = find(x);
            cnt++;
        }
        if (cnt == n - k - 1)
            break;
    }
    if (cnt < n - k - 1)
    {
        cout << "No" << endl;
        return;
    }
    for (int i = 1; i <= k; i++)
    {
        if (st[a[i]] != 2)
        {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
    for (auto x : r)
    {
        if (!st[x])
        {
            st[x] = 1;
            res.push_back(x);
        }
    }
    queue<int> heap;
    heap.push(t);
    cnt = 0;
    while (!heap.empty())
    {
        cnt++;
        int o = heap.front();
        // cout << o << endl;
        heap.pop();
        for (auto p : ans[o])
        {
            if (p == o)
                continue;
            if (ans[p].size() > 0)
                heap.push(p);
        }
    }
    cout << cnt << endl;
    heap.push(t);
    while (!heap.empty())
    {
        cnt++;
        int o = heap.front();
        heap.pop();
        cout << o << " ";
        cout << ans[o].size() << " ";
        for (auto p : ans[o])
        {
            cout << p << " ";
            if (ans[p].size() > 0)
                heap.push(p);
        }
        cout << endl;
    }
}
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T = 1;
    // cin >> T;
    while (T--)
        solve();
    return 0;
}

詳細信息

answer.code: In function ‘void solve()’:
answer.code:102:19: error: ‘r’ was not declared in this scope
  102 |     for (auto x : r)
      |                   ^
answer.code:107:13: error: ‘res’ was not declared in this scope
  107 |             res.push_back(x);
      |             ^~~