Submission #525557

#TimeUsernameProblemLanguageResultExecution timeMemory
525557mjhmjh1104Mountains and Valleys (CCO20_day1problem3)C++17
3 / 25
397 ms82508 KiB
#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)

Main.cpp: In function 'int main()':
Main.cpp:28:62: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   28 |     for (int i = 0; i < n; i++) res = min(res, f(i, (1 << n) - 1 ^ 1 << i));
      |                                                     ~~~~~~~~~^~~
Main.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%d%d%d", &x, &y, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...