QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#657440 | #7738. Equivalent Rewriting | PandaGhost | WA | 1ms | 6432kb | C++17 | 1.5kb | 2024-10-19 14:46:19 | 2024-10-19 14:46:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OPFI(x) freopen(#x".in", "r", stdin);\
freopen(#x".out", "w", stdout)
#define REP(i, a, b) for(int i=(a); i<=(b); ++i)
#define REPd(i, a, b) for(int i=(a); i>=(b); --i)
inline ll rd(){
ll r=0, k=1; char c; while(!isdigit(c=getchar())) if(c=='-') k=-k;
while(isdigit(c)) r=r*10+c-'0', c=getchar(); return r*k;
}
constexpr int N=1e5+10;
ll t, n, m, lst[N], in[N];
vector<int> g[N];
ll ans[N];
int main(){
t=rd();
while(t--){
n=rd(), m=rd();
REP(i, 1, n) in[i]=0, g[i].clear(), ans[i]=0;
REP(i, 1, m) lst[i]=0;
REP(i, 1, n){
ll p=rd();
while(p--){
ll a=rd();
if(lst[a]){
g[lst[a]].push_back(i);
++in[i];
}
lst[a]=i;
}
}
ll cnt=0;
priority_queue<int> q;
REP(i, 1, n)
if(!in[i]) q.push(i);
while(!q.empty()){
int u=q.top(); q.pop();
ans[++cnt]=u;
for(int x:g[u]){
--in[x];
if(in[x]==0) q.push(x);
}
}
int flag=false;
REP(i, 1, n) if(ans[i]!=i) flag=true;
if(flag){
puts("Yes");
REP(i, 1, n) printf("%lld ", ans[i]);
puts("");
}else puts("No");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 6432kb
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: 6280kb
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)