10分pts,求调,玄3关
查看原帖
10分pts,求调,玄3关
1482261
dengruijie3楼主2024/10/17 13:44

rt

#include<bits/stdc++.h>
#define int long long
using namespace std;

int n, m;
int s[2005];
bool f[2005];

struct d{
	int id, what;
}a[2005];

signed main(){	
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> m;
		a[i].id = i;
		if (m == 0){
			int b;
			cin >> b;
			a[i].what = b; 
		}
		else{
			for (int j = 1; j <= m; j++){
				int b;
				cin >> b;
				a[i].what = b;
			}
		}
	}
	int cnt = 0, where = 0;
	for (int i = 1; i <= n; i++){
		if (a[i].what == -1){
			s[++cnt] = i;
			f[i] = 1;
			where = i;
			break;
		}
	}
	while(where){
		int fd = where;
		for (int i = 1; i <= n; i++){
			if (a[i].what == where){
				s[++cnt] = a[i].id;
				f[i] = 1;
				where = a[i].id;
				break;
			}
		}	
		if (fd == where) break;
	}
	for (int i = 1; i <= n; i++) if (f[i] == 0) cout << i << ' ';
	for (int i = cnt; i >= 1; i--) cout << s[i] << ' '; 
	return 0;
} 

2024/10/17 13:44
加载中...