# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
525557 | mjhmjh1104 | Mountains and Valleys (CCO20_day1problem3) | C++17 | 397 ms | 82508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
int n, m, dp[20][20971520];
vector<pair<int, int>> adj[20];
int f(int x, int y) {
if (dp[x][y] + 1) return dp[x][y];
if (!y) return dp[x][y] = 0;
dp[x][y] = (int)1e9;
for (auto &i: adj[x]) dp[x][y] = min(dp[x][y], i.second + f(i.first, y & ~(1 << i.first)));
return dp[x][y];
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) for (int j = 0; j < 1 << n; j++) dp[i][j] = -1;
while (m--) {
int x, y, w;
scanf("%d%d%d", &x, &y, &w);
adj[x].push_back({ y, w });
adj[y].push_back({ x, w });
}
int res = (int)1e9;
for (int i = 0; i < n; i++) res = min(res, f(i, (1 << n) - 1 ^ 1 << i));
printf("%d", res);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |