QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#633436#7738. Equivalent RewritingCUHK_723WA 0ms9276kbC++142.2kb2024-10-12 15:23:222024-10-12 15:23:25

Judging History

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

  • [2024-10-12 15:23:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9276kb
  • [2024-10-12 15:23:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline int read() {
	int x = 0;
	char ch = getchar();
	while(ch < '0' || ch > '9') {
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return x;
} 
int T, n, m;
int a[100010], in[100010], out[100010], arga[100010];
vector<int> f[100010], e[100010];
void solve() {
	if(m == 1) {
		cout << "No";
		return;
	}
	queue<int> s;
	for(int i = 1; i <= n; ++i) {
		if(f[i].size() <= 1) continue;
		for(int j = 1; j < f[i].size(); ++j) {
			int x = f[i][j], y = f[i][j - 1];
			swap(x, y);
			e[x].push_back(y);
			in[y] += 1;
			out[x] += 1;
		}
	}
	int num = 0;
	queue<int> q;
	for(int i = 1; i <= m; ++i) {
		if(in[i] == 0 && out[i] == 0) {
			cout << i << endl;
			s.push(i);
			num += 1;
			continue;
		}
		if(in[i] == 0) q.push(i); 
	}
	num = m - num;
	int ans = 0;
	while(!q.empty()) {
		int x = q.front();
		q.pop();
		ans += 1;
		arga[ans] = x;
		//cout << e[x].size() << endl;
		for(int i = 0; i < e[x].size(); ++i) {
			int y = e[x][i];
			in[y] -= 1;
			if(in[y] == 0) q.push(y);
		}
	}
	if(num < m && num == ans) {
		cout << "Yes" << endl;
		int op = 0;
		if(s.front() == 1) {
			s.pop();
			op = 1;
		}
		while(!s.empty()) {
			cout << s.front() << " ";
			s.pop();
		}
		for(int i = 1; i < ans; ++i) cout << arga[i] << " ";
		cout << arga[num];
		if(op == 1) {
			cout << " " << 1 << endl;
		}
		else cout << endl;
	}
	else if(num != ans) {
		cout << "No" << endl;
	}
	else {
		for(int i = 1; i <= num; ++i) {
			if(arga[i] != i) {
				break;
			}
			if(i == num) {
				cout << "No" << endl;
				return;
			}
		}
		cout << "Yes" << endl;
		for(int i = 1; i < num; ++i) {
			cout << arga[i] << " ";
		}
		cout << arga[num] << endl;
	}
}
int main() {
	T = read();
	while(T) {
		T -= 1;
		m = read();
		n = read();
		int num, x;
		for(int i = 1; i <= n; ++i) {
			arga[i] = 0;
			in[i] = 0;
			out[i] = 0;
			a[i] = 0;
			f[i].clear();
			e[i].clear();
		}
		for(int i = 1; i <= m; ++i) {
			num = read();
			for(int j = 1; j <= num; ++j) {
				x = read();
				a[x] = i;
				f[x].push_back(i);
			}
		}
		solve();
	
	
	
	}
	
	
	
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 9276kb

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:

3
Yes
3 1 2
No
No

result:

wrong answer Token parameter [name=yesno] equals to "3", doesn't correspond to pattern "Yes|No" (test case 1)