QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#767244#7738. Equivalent RewritingguangxuautumnRE 0ms3864kbC++141.3kb2024-11-20 20:19:482024-11-20 20:19:53

Judging History

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

  • [2024-11-20 20:19:53]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3864kb
  • [2024-11-20 20:19:48]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

void solve()
{
	int n, m;

	cin >> n >> m;

	vector<set<int>> p(m);

	for(int i = 0; i < n; i ++) {
		int tp;
		cin >> tp;
		for(int j = 0; j < tp; j ++) {
			int t;
			cin >> t;

			p[i].insert(t);
		}
	}
/*
	for(int i = 0; i < n; i ++) {
		for(auto pp:p[i]) cout << pp <<' ';
			cout << endl;
	}
*/	
	set<int> s;

	for(int i = n - 1; i >= 1; i --) {
		//与后方比,如果在后方出现则抹去;
		for(auto pp:p[i]) {
			if(s.find(pp) != s.end()) p[i].erase(pp);
		}
		//cout << i << ' ' << p[i].size() << endl;
		//与i-1比,若没有交集则可换
		bool flag = 0;
		for(auto pp:p[i]) {
			//find == s.end 意味着没找到
			if(p[i-1].find(pp) != p[i-1].end()) {
				//for(auto ip:p[i-1]) cout << ip << ' ';
				//	cout << endl;
				//cout << "test" << pp << endl;
				flag = 1;
				break;
			}
		}
		if(!flag) {
			//输出正解
			cout << "Yes\n";
			for(int j = 0; j < n; j ++) {
				if(j == i - 1) cout << i + 1 << ' ';
				else if(j == i) cout << i - 1 + 1 << ' ';
				else cout << j + 1 << ' ';
			}
			cout << '\n';
			return;
		}
		//插入后方大set
		for(auto pp:p[i]) s.insert(pp);
	}

	cout << "No\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;


	while(t--)
		solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
1 3 2 
No
No

result:

ok OK. (3 test cases)

Test #2:

score: -100
Runtime Error

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:


result: