QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#346978 | #7738. Equivalent Rewriting | ucup-team3160# | WA | 9ms | 50588kb | C++17 | 1.7kb | 2024-03-09 09:21:24 | 2024-03-09 09:21:26 |
Judging History
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;
}
}
詳細信息
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)