QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#346978#7738. Equivalent Rewritingucup-team3160#WA 9ms50588kbC++171.7kb2024-03-09 09:21:242024-03-09 09:21:26

Judging History

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

  • [2024-03-09 09:21:26]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:50588kb
  • [2024-03-09 09:21:24]
  • 提交

answer

#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include "lib.h"
#endif
#define rep(i, min, max) for(int i = (min); i <= (max); ++i)
#define nrep(i, max, min) for(int i = (max); i >= (min); --i)
#define reads(str) (scanf("%s", str + 1), strlen(str + 1))
#define case() int Ts = read(); rep(T, 1, Ts)
#define putf(flag) puts((flag) ? "Yes" : "No")
#define put(x) printf("%d ", x)
#define putl(x) printf("%lld ", x)
#define endl() putchar('\n')
using namespace std;

typedef long long ll;
inline int read()
{
    int now=0; bool nev=false; char c=getchar();
    while(c<'0' || c>'9') { if(c=='-') nev=true; c=getchar(); }
    while(c>='0' && c<='9') { now=(now<<1)+(now<<3)+(c&15); c=getchar(); }
    return nev?-now:now;
}

const int N = 2e6 + 10;

int out[N];
int a[N];
int ord[N], top;
vector<int> to[N];

int main() {
    case() {
        int n = read(), m = read();
        rep(i, 1, n) {
            int p = read();
            rep(j, 1, p) {
                int x = read();
                out[a[x]] ++;
                to[i].push_back(a[x]);
                a[x] = i;
            }
        }
        priority_queue<int, vector<int>, greater<int>> heap;
        top = n;
        rep(i, 1, n) if(!out[i]) heap.push(i);
        while(!heap.empty()) {
            int x = heap.top(); heap.pop();
            ord[top--] = x;
            for(int y : to[x]) {
                out[y] --;
                if(!out[y]) heap.push(y);
            }
        }
        bool fl = 0;
        rep(i, 1, n) fl |= ord[i] != i;
        putf(fl);
        if(fl) {
            rep(i, 1, n) put(ord[i]); endl();
        }
        rep(i, 0, max(n, m)) a[i] = 0, to[i] = {}, out[i] = 0;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 50588kb

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: 9ms
memory: 50400kb

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)