Submission #66597

#TimeUsernameProblemLanguageResultExecution timeMemory
66597BruteforcemanPaths (BOI18_paths)C++11
100 / 100
726 ms183732 KiB
#include "bits/stdc++.h" using namespace std; int k; vector <int> g[300010]; int col[300010]; long long M[1 << 5][300010]; long long dp(int mask, int node) { if(M[mask][node] != -1) return M[mask][node]; long long ans = 1; for(auto i : g[node]) { if((mask >> col[i]) & 1) {} else { ans += dp(mask ^ (1 << col[i]), i); } } return M[mask][node] = ans; } int main(int argc, char const *argv[]) { int n, m; scanf("%d %d %d", &n, &m, &k); for(int i = 1; i <= n; i++) { scanf("%d", &col[i]); --col[i]; } for(int i = 0; i < m; i++) { int p, q; scanf("%d %d", &p, &q); g[p].push_back(q); g[q].push_back(p); } memset(M, -1, sizeof M); long long ans = 0; for(int i = 1; i <= n; i++) { ans += dp(1 << col[i], i); } printf("%lld\n", ans - n); return 0; }

Compilation message (stderr)

paths.cpp: In function 'int main(int, const char**)':
paths.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &m, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &col[i]);
   ~~~~~^~~~~~~~~~~~~~~
paths.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &p, &q);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...