当前位置:网站首页>L2-031 深入虎穴 (25 分) (dfs
L2-031 深入虎穴 (25 分) (dfs
2022-04-22 09:17:00 【lcxdz】
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+9;
int in[N];
vector<int>v[N];
int mx,ans;
void dfs(int u,int fa,int deep){
if(deep>mx){
mx=deep;
ans=u;
}
for(auto it:v[u]){
if(fa==it)continue;
dfs(it,u,deep+1);
}
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
int k;
cin>>k;
for(int j=1;j<=k;j++){
int x;
cin>>x;
v[i].push_back(x);
in[x]++;
}
}
int root=-1;
for(int i=1;i<=n;i++){
if(in[i]==0){
root=i;
break;
}
}
dfs(root,-1,1);
cout<<ans<<"\n";
return 0;
}
版权声明
本文为[lcxdz]所创,转载请带上原文链接,感谢
https://minelois.blog.csdn.net/article/details/124331783
边栏推荐
猜你喜欢
随机推荐
六个方法,可以让你在NFT交易中收益更多
sqlserver 数据传输到 mysql
2022 R1 quick opening pressure vessel operation exercises and online simulation examination
A 2500 word article will take you to understand the basic knowledge of performance testing
Separate linked list (create two empty linked lists)
从科普、医生培训及创新医械产品推广需求出发,「佰医绘」如何布局医学可视化SaaS服务?
泳道跨域问题
量化投资学习——介绍orderflow
Understand the first snapshot read and the second snapshot read of the same transaction in MySQL mvcc - Notes
LeetCode 283. 移动零(简单、数组)day12
pip install shutil 报错
Gym member management system requirements analysis document
安装Navicat 15 详解及相关问题详解
找出二维数组最大的一个数
Using stack to realize queue (double stack, input stack and output stack)
Using docker to build LNMP + redis development environment suitable for thinkphp5
C 标准库 - <time.h>
web 学习记录(中)
Oracle 18C RAC installation grid execution script root SH error, prcr-1013: unable to start resource ora ons
手動搭建hyperledger fabric v2.x 生產網絡(四)創建通道,鏈碼的生命周期









