Submission #135680

#TimeUsernameProblemLanguageResultExecution timeMemory
135680PlurmPaths (BOI18_paths)C++11
100 / 100
919 ms25580 KiB
#include <bits/stdc++.h> using namespace std; vector<int> g[300005]; long long dp[300005]; int col[300005]; vector<int> bckt[8]; int sel[8]; int n; long long iteratePerm(int k, int c, int lv = 1){ if(lv == c+1){ for(int i = 1; i <= n; i++) dp[i] = 0ll; for(int u : bckt[sel[1]]) dp[u] = 1ll; for(int step = 2; step <= c; step++){ for(int u : bckt[sel[step]]){ for(int v : g[u]){ if(col[v] == sel[step-1]) dp[u] += dp[v]; } } } long long sum = 0ll; for(int i = 1; i <= n; i++){ if(col[i] == sel[c]){ sum += dp[i]; } } return sum; }else{ long long sum = 0ll; for(int i = 1; i <= k; i++){ bool ok = true; for(int j = 1; j < lv; j++){ if(sel[j] == i) ok = false; } if(ok){ sel[lv] = i; sum += iteratePerm(k, c, lv+1); sel[lv] = 0; } } return sum; } } int main(){ int m,k; scanf("%d%d%d",&n,&m,&k); for(int i = 1; i <= n; i++){ scanf("%d",col+i); bckt[col[i]].push_back(i); } for(int i = 0; i < m; i++){ int u,v; scanf("%d%d",&u,&v); g[u].push_back(v); g[v].push_back(u); } long long ans = 0ll; for(int i = 2; i <= k; i++){ ans += iteratePerm(k,i); } printf("%lld\n",ans); return 0; }

Compilation message (stderr)

paths.cpp: In function 'int main()':
paths.cpp:45:10: 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:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",col+i);
         ~~~~~^~~~~~~~~~~~
paths.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&u,&v);
         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...