QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#346981#7738. Equivalent Rewritingucup-team3160#WA 19ms101196kbC++171.8kb2024-03-09 09:26:282024-03-09 09:26:29

Judging History

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

  • [2024-03-09 09:26:29]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:101196kb
  • [2024-03-09 09:26:28]
  • 提交

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], vis[N];

int main() {
    case() {
        int n = read(), m = read();
        rep(i, 1, n) {
            int p = read();
            rep(j, 1, p) {
                int x = read();
                vis[x].push_back(a[x]);
                a[x] = i;
            }
        }
        rep(x, 1, m) for(int i : vis[x]) out[i] ++, to[a[x]].push_back(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] = vis[i] = {}, out[i] = 0;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 99896kb

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: 19ms
memory: 101196kb

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
7 6 5 4 3 2 1 0 9 10 

result:

wrong answer Integer parameter [name=q_i] equals to 0, violates the range [1, 10] (test case 1)