solution
P1075的简单变形
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct node{
int data, next;
}list[100000];
int main(){
int first1, first2, n, addr;
vector<int> l1, l2, ans;
scanf("%d%d%d", &first1, &first2, &n);
for(int i = 0; i < n; i++){
scanf("%d", &addr);
scanf("%d%d", &list[addr].data, &list[addr].next);
}
while(first1 != -1){
l1.push_back(first1);
first1 = list[first1].next;
}
while(first2 != -1){
l2.push_back(first2);
first2 = list[first2].next;
}
if(l2.size() > l1.size()) swap(l1, l2);
for(int i = 0, j = l2.size() - 1; i < l1.size(); i++){
ans.push_back(l1[i]);
if(j >= 0 && i % 2) ans.push_back(l2[j--]);
}
for(int i = 0; i < ans.size(); i++){
if(i == 0) printf("%05d %d ", ans[i], list[ans[i]].data);
else printf("%05d\n%05d %d ", ans[i], ans[i], list[ans[i]].data);
}
printf("-1");
return 0;
}