Submission #62820

#TimeUsernameProblemLanguageResultExecution timeMemory
62820SpaimaCarpatilorPaths (BOI18_paths)C++17
100 / 100
688 ms102932 KiB
#include<bits/stdc++.h> using namespace std; int N, M, K, c[300009]; long long *dp[32]; vector < int > v[300009]; int main () { //freopen ("input", "r", stdin); //freopen ("output", "w", stdout); scanf ("%d %d %d", &N, &M, &K); for (int i=1; i<=N; i++) scanf ("%d", &c[i]), c[i] --; while (M --) { int x, y; scanf ("%d %d", &x, &y); v[x].push_back (y); v[y].push_back (x); } for (int i=0; i<(1 << K); i++) dp[i] = new long long[N + 1] (); long long ans = 0; for (int msk = 1; msk < (1 << K); msk ++) for (int i=1; i<=N; i++) if ((msk >> c[i]) & 1) { if (msk == (1 << c[i])) dp[msk][i] = 1; else { for (auto j : v[i]) dp[msk][i] += dp[msk ^ (1 << c[i])][j]; } ans += dp[msk][i]; /* if (dp[msk][i] > 0) printf ("(%d, %d) -> %lld\n", msk, i, dp[msk][i]);*/ } printf ("%lld\n", ans - N); return 0; }

Compilation message (stderr)

paths.cpp: In function 'int main()':
paths.cpp:14: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:16:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d", &c[i]), c[i] --;
     ~~~~~~~~~~~~~~~~~~~^~~~~~~~~
paths.cpp:20:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d %d", &x, &y);
     ~~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...