|
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <string>
- #include <queue>
- using namespace std;
- struct edge {
- int end;
- int len;
- };
- struct data {
- string way;
- int len;
- bool operator<(const data &x) const {
- return len > x.len;
- }
- };
- priority_queue<data> Q;
- vector<edge> V[51];
- data w;
- bool B[51];
- int A[51];
- int m, n, k, a, b, cnt;
- string change(int x)
- {
- string s;
- do {
- s += char((x % 10) + '0');
- x /= 10;
- } while (x > 0);
- reverse(s.begin(), s.end());
- return s;
- }
- void put(int x)
- {
- w.way += change(x);
- w.way += '-';
- }
- void del()
- {
- string s = w.way;
- int i = s.size() - 2;
- while (s[i] != '-' && i >= 0);
- --i;
- w.way = s.substr(0, i + 1);
- }
- void add(int u, int v, int l)
- {
- edge tmp;
- tmp.end = v;
- tmp.len = l;
- V[u].push_back(tmp);
- }
- void dfs(int p)
- {
- if (p == b) {
- cout << w.way << endl;
- Q.push(w);
- ++cnt;
- }
- else {
- for (int i = 0; i != V[p].size(); ++i) {
- if (!B[V[p][i].end]) {
- B[V[p][i].end] = true;
- put(V[p][i].end);
- w.len += V[p][i].len;
- dfs(V[p][i].end);
- B[V[p][i].end] = false;
- w.len -= V[p][i].len;
- del();
- }
- }
- }
- }
- int main()
- {
- cin >> n >> m >> k >> a >> b;
- for (int i = 0, u, v, l; i != m; ++i) {
- cin >> u >> v >> l;
- add(u, v, l);
- }
- put(a);
- B[a] = true;
- dfs(a);
- if (cnt < k)
- cout << "No";
- else {
- for (int i = 1; i <= k - 1; ++i)
- Q.pop();
- cout << Q.top().way;
- }
- return 0;
- }
复制代码 |
|