QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#275339#7738. Equivalent Rewriting666ldcWA 0ms3600kbC++141.8kb2023-12-04 16:59:052023-12-04 16:59:05

Judging History

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

  • [2023-12-04 16:59:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3600kb
  • [2023-12-04 16:59:05]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define all(x) (x).begin(), (x).end()
using pii = std::pair<int, int>;
void solve()
{
    int n, m;
    std::cin >> n >> m;
    std::vector<std::vector<int>> p(n + 1);
    for (int i = 1; i <= n; i ++)
    {
        int x;
        std::cin >> x;
        for (int j = 0; j < x; j ++)
        {
            int y;
            std::cin >> y;
            p[i].push_back(y);
        }
    }
    std::vector<std::vector<int>> adj(n + 1);
    std::vector<int> num(m + 1);
    std::vector<int> din(n + 1);
    for (int i = 1; i <= n; i ++)
    {
        for (int j = 0; j < p[i].size(); j ++)
        {
            if (!num[p[i][j]]) num[p[i][j]] = i;
            else
            {
                adj[num[p[i][j]]].push_back(i);
                din[i] ++;
                num[p[i][j]] = i;
            }
        }
    }
    std::vector<int> q(n);
    int hh = 0, tt = -1;
    for (int i = 1; i <= n; i ++)
        if (!din[i])
            q[++ tt] = i;
    std::vector<int> cnt(n);
    std::iota(all(cnt), 1);
    for (int i = 1; i <= n; i ++)
        std::sort(adj[i].rbegin(), adj[i].rend());
    while (hh <= tt)
    {
        int t = q[hh ++ ];
        for (auto j : adj[t])
        {
            if (-- din[j] == 0)
                q[++ tt] = j;
        }
    }
    bool ok = false;
    for (int i = 0; i < n; i ++)
        if (cnt[i] != q[i])
        {
            ok = true;
            break;
        }
    if (!ok) std::cout << "No\n";
    else
    {
        std::cout << "Yes\n";
        for (int i = 0; i < n; i ++)
            std::cout << q[i] << " \n"[i == n - 1];
    }
}
signed main()
{
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int T = 1;
    std::cin >> T;
    while (T --) solve();
    return 0;
}

詳細信息

Test #1:

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

input:

3
3 6
3 3 1 5
2 5 3
2 2 6
2 3
3 1 3 2
2 3 1
1 3
2 2 1

output:

Yes
1 3 2
No
No

result:

ok OK. (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3568kb

input:

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

output:

No

result:

wrong answer jury found an answer but participant did not (test case 1)