QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#633851#7738. Equivalent RewritingCUHK_723WA 4ms10592kbC++141.7kb2024-10-12 16:18:362024-10-12 16:18:40

Judging History

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

  • [2024-10-12 16:18:40]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:10592kb
  • [2024-10-12 16:18:36]
  • 提交

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], ans[1000010];
vector<int> f[100010], e[100010];
void solve() {
	for(int i = 1; i <= n; ++i) {
		if(f[i].size() <= 1) continue;
		int x = f[i][f[i].size() - 1], y;
		for(int j = 0; j < f[i].size() - 1; ++j) {
			y = f[i][j];
			e[y].push_back(x);
			in[x] += 1;
			out[y] += 1;
		}
	}
	queue<int> q;
	int cnt = 0, op = 0;
	if(in[1] == 0 && out[1] == 0) op = 1;
	else if(in[1] == 0) q.push(1);
	for(int i = 2; i <= m; ++i) {
		if(in[i] == 0 && out[i] == 0) {
			ans[++cnt] = i;
			continue;
		}
		if(in[i] == 0) q.push(i);
	}
	while(!q.empty()) {
		int x = q.front();
		q.pop();
		ans[++cnt] = x;
		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(op == 1) ans[++cnt] = 1;
	if(cnt < m) {
		cout << "No" << endl;
		return;
	} 
	for(int i = 1; i <= m; ++i) {
		if(ans[i] != i) break;
		if(i == m) {
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
	for(int i = 1; i < m; ++i) cout << ans[i] << " ";
	cout << ans[cnt] << endl;
}
int main() {
	T = read();
	while(T) {
		T -= 1;
		m = read();
		n = read();
		int num, x;
		for(int i = 1; i <= n; ++i) {
			a[i] = 0;
			in[i] = 0;
			out[i] = 0;
			ans[i] = 0;
			f[i].clear();
		} 
		for(int i = 1; i <= m; ++i) {
			num = read();
			for(int j = 1; j <= num; ++j) {
				x = read();
				f[x].push_back(i);
				a[x] = i;
			}
		}
		solve();
	}
	
	
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 4ms
memory: 10592kb

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)