#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int solution(int N, vector<vector<int> > road, int K) {
int answer = 0;
int i, j ,k, m, num, num2, city;
sort(road.begin(), road.end());
vector <int> uniq;
uniq.push_back(1);
int tmp, tmp2;
for(i=0; i < road.size(); i++){
tmp = 0;
for(j = 0; j < 2; j++){
if(road[i][j] == 1){
num = abs(j-1);
city = road[i][num];
tmp += road[i][2];
if( tmp > K)
break;
uniq.push_back(city);
for(k = i + 1; k < road.size(); k++){
cout << "k: " << k << " ";
for(m =0; m < 2; m++ ){
if(road[k][m] == city){
tmp += road[k][2];
if(tmp > K){
tmp -= road[k][2];
continue;
}
num2 = abs(m-1);
uniq.push_back(road[k][num2]);
tmp -= road[k][2];
}
}
}
}
}
}
for(i =0; i < uniq.size(); i++)
cout << uniq[i] << " ";
cout << endl;
sort(uniq.begin(), uniq.end());
uniq.erase(unique(uniq.begin(), uniq.end()), uniq.end());
for(i =0 ;i < uniq.size(); i++)
cout << uniq[i] << " ";
answer = uniq.size();
return answer;
}