QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#595026 | #7738. Equivalent Rewriting | zhangboju# | WA | 1ms | 7896kb | C++14 | 1.7kb | 2024-09-28 12:09:31 | 2024-09-28 12:09:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e6+10;
struct edge {
int v,nxt;
}e[MAXN<<1];
int n,m,sz,cnt,tot;
int pre[MAXN],h[MAXN],ind[MAXN],ans[MAXN];
queue<int> q;
void output() {
for(int i=1;i<=n;i++) {
printf("%d ",ans[i]);
}
puts("");
}
void addedge(int u,int v) {
e[++cnt].v=v;
e[cnt].nxt=h[u];
h[u]=cnt;
ind[v]++;
}
void clear() {
for(int i=1;i<=n;i++) {
ans[i]=ind[i]=h[i]=0;
}
for(int i=1;i<=m;i++) {
pre[i]=0;
}
while(!q.empty()) {
q.pop();
}
sz=n=m=cnt=tot=0;
}
void solve() {
cin>>n>>m;
for(int i=1;i<=n;i++) {
int k;
scanf("%d",&k);
while(k--) {
int x;
scanf("%d",&x);
if(pre[x]) {
addedge(pre[x],i);
}
pre[x]=i;
}
}
for(int i=1;i<=n;i++) {
if(!ind[i]) {
q.push(i);
sz++;
}
}
bool flag=0;
while(!q.empty()) {
if(sz>1&&!flag) {
flag=1;
if(q.front()==tot+1) {
q.push(q.front());
q.pop();
}
}
int u=q.front();
ans[++tot]=u;
sz--;
q.pop();
for(int i=h[u];i;i=e[i].nxt) {
int v=e[i].v;
ind[v]--;
if(!ind[v]) {
q.push(v);
sz++;
}
}
}
if(flag) {
puts("Yes");
output();
}
else {
puts("No");
}
clear();
return ;
}
int main() {
int t;
cin>>t;
while(t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7896kb
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: 0ms
memory: 7796kb
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)