博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
给任意多个链表然后要合并成一个
阅读量:4312 次
发布时间:2019-06-06

本文共 861 字,大约阅读时间需要 2 分钟。

 

 

 

 

 

 

 

 

 

 

#include
#include
#include
#include
using namespace std;const int N=110;int pre[N],nex[N];int z[N],y[N];int wan[N];int fa[N];int findx(int x){ return fa[x]=(x==fa[x]?x:findx(fa[x]));}int main(){ int n; scanf("%d",&n); int tot1=0,tot2=0,tot3=0; for(int i=0; i<=n; ++i) fa[i]=i; for(int i=1; i<=n; ++i) { scanf("%d%d",&pre[i],&nex[i]); int x1=findx(i),x2=findx(pre[i]),x3=findx(nex[i]); if(x1!=x2&&x2!=0) fa[x2]=x1; if(x1!=x3&&x3!=0) fa[x3]=x1; if(pre[i]==0&&nex[i]==0) { wan[tot2++]=i; continue; } if(pre[i]==0) z[tot1++]=i; if(nex[i]==0) y[tot3++]=i; } bool used[120]; memset(used,0,sizeof(used)); for(int i=0; i

 

转载于:https://www.cnblogs.com/mfys/p/7553129.html

你可能感兴趣的文章
HTTP协议
查看>>
HTTPS
查看>>
git add . git add -u git add -A区别
查看>>
apache下虚拟域名配置
查看>>
session和cookie区别与联系
查看>>
PHP 实现笛卡尔积
查看>>
Laravel中的$loop
查看>>
CentOS7 重置root密码
查看>>
Centos安装Python3
查看>>
PHP批量插入
查看>>
laravel连接sql server 2008
查看>>
Laravel框架学习笔记之任务调度(定时任务)
查看>>
laravel 定时任务秒级执行
查看>>
浅析 Laravel 官方文档推荐的 Nginx 配置
查看>>
Swagger在Laravel项目中的使用
查看>>
Laravel 的生命周期
查看>>
CentOS Docker 安装
查看>>
Nginx
查看>>
Navicat远程连接云主机数据库
查看>>
Nginx配置文件nginx.conf中文详解(总结)
查看>>