QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#634030#7738. Equivalent RewritingCUHK_723WA 0ms9400kbC++141.9kb2024-10-12 16:35:422024-10-12 16:35:44

Judging History

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

  • [2024-10-12 16:35:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9400kb
  • [2024-10-12 16:35:42]
  • 提交

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[100010];
vector<int> f[100010], e[100010];
queue<int> q;
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;
			//cout << y << "F" << x << endl;
		}
		
	}
	
	int cnt = 0, op = 0;
	
	for(int i = m; i >= 2; --i) {
		if(in[i] == 0 && out[i] == 0) {
			ans[++cnt] = i;
			continue;
		}
		if(in[i] == 0) q.push(i);
	}
	if(in[1] == 0 && out[1] == 0) op = 1;
	else if(in[1] == 0) q.push(1);
	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;
	//for(int i = 1; i <= cnt; ++i) cout << ans[i] << " ";
	//cout << endl;
	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) printf("%d", ans[i]);
	printf("%d\n", ans[cnt]);
}
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: 0
Wrong Answer
time: 0ms
memory: 9400kb

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
312
No
No

result:

wrong answer Integer parameter [name=q_i] equals to 312, violates the range [1, 3] (test case 1)