链表合并模板题,注意分清楚边界条件
#include<bits/stdc++.h>
using namespace std;
struct Node{
int data,ad,next;
}node[100100];
vector<Node>p1,p2,p3;
int main(){
int f1,f2,n,ad,data;
cin>>f1>>f2>>n;
for(int i=0;i<n;i++){
scanf("%d",&ad);
node[ad].ad=ad;
scanf("%d%d",&node[ad].data,&node[ad].next);
}
int now=f1;
while(now!=-1){
p1.push_back(node[now]);
now=node[now].next;
}
now=f2;
while(now!=-1){
p2.push_back(node[now]);
now=node[now].next;
}
if(p2.size()>=2*p1.size()