#include <bits/stdc++.h>
using namespace std;
vector<int> vec[10010],ans;//矩阵
int vis[10010];
int maxLen = 0;
void dfs(int root,vector<int> &v) {
if(v.size() > maxLen){
ans.clear();
ans = v;
maxLen = v.size();
}
for (int i = 0; i < vec[root].size(); i++) {
v.push_back(vec[root][i]);
dfs(vec[root][i], v);
v.pop_back();
}
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {//i起始
int t;
cin >> t;
for (int j = 0; j < t; j++) {
int tno;
cin >> tno;
vec[i].push_back(tno);
vis[tno] = 1;
}
//将里面的元素进行排序
sort(vec[i].begin(),vec[i].end());
}
//找到根
int root = 0;
for (int i = 0; i < n; i++) {
if (vis[i] == 0) {
root = i;
break;
}
}
vector<int> v;
v.push_back(root);
dfs(root,v);
cout << maxLen << '\n';
for (int i = 0; i < ans.size(); i++) {
cout << ans[i];
if (i < ans.size()-1) cout << " ";
}
return 0;
}
标签:int,back,++,038,L2,vec,tno,root,溯源
From: https://www.cnblogs.com/chengyiyuki/p/18089744