QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#695695#7738. Equivalent RewritingAlways#WA 1ms4100kbC++231.8kb2024-10-31 20:36:342024-10-31 20:36:41

Judging History

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

  • [2024-10-31 20:36:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4100kb
  • [2024-10-31 20:36:34]
  • 提交

answer

#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;

priority_queue<int> q;
struct node {
    int to, nxt;
} e[40000006];
int cnt, head[100005];
void add(int x, int y) {
    e[++cnt].to = y;
    e[cnt].nxt = head[x];
    head[x] = cnt;
}

int bu[100005], rd[100005], vis[100005];

int main() {
    int T;
    cin >> T;
    while (T--) {
        int n, m;
        cin >> n >> m;
        for (int i = 1; i <= n; i++) {
            int p;
            cin >> p;
            for (int j = 1; j <= p; j++) {
                int l;
                cin >> l;
                if (bu[l] == 0) {
                    bu[l] = i;
                } else if (vis[bu[l]] == 0 && bu[l] != 0) {
                    add(bu[l], i);
                    rd[i]++;
                    vis[bu[l]] = 1;
                    bu[l] = i;
                }
            }
            for (int j = 1; j <= p; j++)
                vis[j] = 0;  // 清零 vis
        }

        int pd = 0;
        for (int i = 1; i <= n; i++) {
            if (rd[i] == 0) q.push(i);
        }

        int ans[100005], tot = 0;
        while (!q.empty()) {
            int x = q.top();
            q.pop();
            ans[++tot] = x;
            if (tot != x) pd = 1;
            for (int i = head[x]; i != 0; i = e[i].nxt) {
                int y = e[i].to;
                rd[y]--;
                if (rd[y] == 0) q.push(y);
            }
        }

        if (pd == 0) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
            for (int i = 1; i < tot; i++)
                cout << ans[i] << " ";
            cout << ans[tot] << endl;
        }

        for (int i = 1; i <= n; i++)
            bu[i] = rd[i] = head[i] = 0;
        cnt = 0;
    }
    
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 4100kb

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
3 1 2
No
No

result:

ok OK. (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 4052kb

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:

Yes
1 3 2 4 5 10 6 7 8 9

result:

wrong answer two transactions are not equivalent. (test case 1)