便宜建站方法,站外推广方式有哪些,主题猫wordpress,虚拟主机网站500错误活动 - AcWing
有个人的家族很大#xff0c;辈分关系很混乱#xff0c;请你帮整理一下这种关系。
给出每个人的孩子的信息。
输出一个序列#xff0c;使得每个人的孩子都比那个人后列出。
输入格式
第 11 行一个整数 n#xff0c;表示家族的人数#xff1b;
接下来 …活动 - AcWing
有个人的家族很大辈分关系很混乱请你帮整理一下这种关系。
给出每个人的孩子的信息。
输出一个序列使得每个人的孩子都比那个人后列出。
输入格式
第 11 行一个整数 n表示家族的人数
接下来 n 行第 i 行描述第 i 个人的孩子
每行最后是 0 表示描述完毕。
每个人的编号从 1 到 n。
输出格式
输出一个序列使得每个人的孩子都比那个人后列出
数据保证一定有解如果有多解输出任意一解。
数据范围
1≤n≤100
输入样例
5
0
4 5 1 0
1 0
5 3 0
3 0输出样例
2 4 5 3 1
解析 #includeiostream
#includestring
#includecstring
#includecmath
#includectime
#includealgorithm
#includeutility
#includestack
#includequeue
#includevector
#includeset
#includemath.h
#includemap
#includesstream
#includedeque
#includeunordered_map
#includeunordered_set
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pairint, int PII;
const int N 1e25, M 2e4, INF 0x3f3f3f3f;
int n;
int h[N], e[M], ne[M], idx;
int din[N],q[N];
int ans[N], cnt;void add(int a, int b) {e[idx] b, ne[idx] h[a], h[a] idx;
}void topsort() {int hh 0, tt 0;for (int i 1; i n; i) {if (!din[i])q[tt] i;}while (hh ! tt) {int t q[hh];ans[cnt] t;if (hh N)hh 0;for (int i h[t]; i ! -1; i ne[i]) {int j e[i];if (--din[j] 0) {q[tt] j;if (tt N)tt 0;}}}
}int main() {cin n;memset(h, -1, sizeof h);for (int i 1, a; i n; i) {while (cin a, a) {add(i, a);din[a];}}topsort();for (int i 0; i cnt; i) {printf(%d , ans[i]);}return 0;
}