Submission #1268468

#TimeUsernameProblemLanguageResultExecution timeMemory
1268468ducdevPaths (BOI18_paths)C++17
100 / 100
272 ms52272 KiB
// Author: 4uckd3v - Nguyen Cao Duc #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX_N = 3e5; const int MOD = 1e9 + 7; int n, m, k; int color[MAX_N + 5]; ll dp[1 << 5][MAX_N + 5]; vector<int> adj[MAX_N + 5]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); if (fopen("MAIN.INP", "r")) { freopen("MAIN.INP", "r", stdin); freopen("MAIN.OUT", "w", stdout); }; cin >> n >> m >> k; for (int u = 1; u <= n; u++) { cin >> color[u]; color[u]--; }; while (m--) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); }; ll res = 0; for (int u = 1; u <= n; u++) dp[1 << color[u]][u] = 1; for (int mask = 1; mask < (1 << k); mask++) { for (int u = 1; u <= n; u++) { for (int v : adj[u]) { if (mask >> color[v] & 1) continue; dp[mask ^ (1 << color[v])][v] += dp[mask][u]; }; if (__builtin_popcount(mask) > 1) res += dp[mask][u]; }; }; cout << res; };

Compilation message (stderr)

paths.cpp: In function 'int main()':
paths.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen("MAIN.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen("MAIN.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...