1 // UN DIJKSTRA QUE GUARDA CAMINOS.... NO ES TAN TIVIAL COMO APARENTA... IMP
22 #define forn(i, n) for(int i=0;i<int(n);i++)
23 #define foreach(it, c) for(typeof((c).begin()) it = (c).begin();it!=(c).end();++it)
24 #define ALL(x) (x).begin(),(x).end()
25 #define SORT(x) sort(ALL(x))
27 #define VI vector<int>
28 #define VS vector<string>
38 scanf("%i", &N
);if( N
< 0 ) return 0;
39 for(i
=0;i
<=N
;i
++)for(j
=0;j
<=N
;j
++) cost
[i
][j
] = MX
;
40 scanf("%i", &M
);int a
, b
, c
;
42 scanf("%i %i %i", &a
, &b
, &c
);
43 if( a
> N
|| b
> N
) continue;
44 edges
[a
].PB(b
), edges
[b
].PB(a
);
45 cost
[a
][b
] = min(cost
[a
][b
], c
);
46 cost
[b
][a
] = min(cost
[b
][a
],c
);
50 for(i
=1;i
<=N
;i
++)for(j
=i
+1;j
<=N
;j
++){
51 if( cost
[i
][j
] == MX
) continue;
52 set
<pair
<int,int> > Q
;
53 Q
.insert(make_pair(0, i
));
55 memset(visited
, 0, sizeof(visited
));
57 for(k
=0;k
<102;k
++) mark
[k
] = MX
;
59 memset(padre
, -1, sizeof(padre
));
61 pair
<int,int> par
= *(Q
.begin()); Q
.erase(Q
.begin());
62 if( par
.second
== j
) break;
63 if( cost
[i
][j
] + par
.first
>= sum
) break;
64 if( visited
[par
.second
] || par
.first
> mark
[par
.second
] ) continue;
65 visited
[par
.second
] = 1;
66 for(k
=0;k
<edges
[par
.second
].size();k
++){
67 if( par
.second
== i
){
68 if( edges
[par
.second
][k
] == j
) continue;
69 }if( edges
[par
.second
][k
] == i
){
70 if( par
.second
== j
) continue;
72 int dist
= cost
[par
.second
][edges
[par
.second
][k
]] + par
.first
;
73 if( dist
< mark
[edges
[par
.second
][k
]] ){
74 mark
[edges
[par
.second
][k
]] = dist
;
75 Q
.insert(make_pair(dist
, edges
[par
.second
][k
]));
76 padre
[edges
[par
.second
][k
]] = par
.second
;
80 int tot
= mark
[j
] + cost
[i
][j
];
81 if( tot
< sum
&& padre
[j
] > 0){
95 for(i
=0;i
<res
.size();i
++){
96 if( first
) first
= 0; else printf(" ");
100 }else printf("No solution.\n");