QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#674518#7738. Equivalent RewritingdyfhpuWA 0ms3836kbC++171.0kb2024-10-25 16:14:372024-10-25 16:14:37

Judging History

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

  • [2024-10-25 16:14:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3836kb
  • [2024-10-25 16:14:37]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <vector>
using namespace std;
void solve()
{
	int n,m;cin>>n>>m;
	int in[n+10];
	int st[n+10];
	vector<int> v[n+10];
	for(int i=1;i<=n+10;i++) in[i]=0,st[i]=0;
	for(int i=1;i<=n;i++) {
		int x;cin>>x;
		for(int j=1;j<=x;j++) {
			int y;cin>>y;
			int t=st[y];
			st[y]=i;
			if(t!=0) {
				in[i]++;
				v[t].push_back(i);
			}
		}
	}
	queue<int> q;
	int cnt=0;
	for(int i=n;i>=1;i--) {
		if(in[i]==0) {
			q.push(i);cnt++;
		}
	}
	if(cnt<2) {
		cout<<"No"<<endl;
		return ;
	}
	
	queue<int> s;
	while(q.size()) {
		int t=q.front();
		s.push(t);q.pop();
		for(auto f:v[t]) {
			in[f]--;
			if(in[f]==0) {
				q.push(f);
			}
		}
	} 
	if(s.size()==n) {
		cout<<"Yes"<<endl;
		while(s.size()) {
			cout<<s.front()<<' ';
			s.pop();
		}
		cout<<endl;
	}
	else cout<<"No"<<endl;
	return ;
}
signed main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3752kb

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: 3836kb

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)