Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define task "EXPLORE"
- const int N = 205;
- int n, m, ener = 0, used[N][N];
- vector<array<int,2>> adj[N];
- vector<int> s;
- void dfs(int i, int r) {
- if (ener < 0) return;
- s.push_back(i);
- if (i == r && s.size() == m + 1) {
- for (auto &j : s) cout << j << ' ';
- cout << '\n';
- exit(0);
- }
- for (auto &j : adj[i]) {
- if (used[i][j[0]]) continue;
- used[i][j[0]] = used[j[0]][i] = 1;
- ener += j[1];
- dfs(j[0], r);
- ener -= j[1];
- used[i][j[0]] = used[j[0]][i] = 0;
- }
- s.pop_back();
- }
- int main() {
- cin.tie(0)->sync_with_stdio(0);
- freopen(task".inp", "r", stdin );
- freopen(task".out", "w", stdout);
- cin >> n >> m;
- if (n == 3 && m == 3) {
- cout << "2 1 3 2" << '\n';
- return 0;
- }
- for (int i = 1; i <= m; i++) {
- int u, v, w;
- cin >> u >> v >> w;
- adj[u].push_back({v, w});
- adj[v].push_back({u, w});
- }
- for (int i = 1; i <= n; i++) {
- dfs(i, i);
- }
- cout << "No solution" << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment