Submission #104885

#TimeUsernameProblemLanguageResultExecution timeMemory
104885groeneprofPaths (BOI18_paths)C++14
100 / 100
1026 ms74612 KiB
#include <bits/stdc++.h> #define int long long #define P(x) do {if(debug) cout << x << endl;} while(false) #define H(x) P(#x << ": " << x) #define FR(i, a, b) for(int i = (a); i < (b); ++i) #define F(i, n) FR(i, 0, n) #define DR(i, a, b) for(int i = (b); i --> (a);) #define D(i, n) DR(i, 0, n) #define S(s) (int)(s).size() #define ALL(x) (x).begin(), (x).end() #define MI(x, a) (x) = min(x, a) #define MA(x, a) (x) = max(x, a) #define V vector #define pb push_back #define mp make_pair using namespace std; const bool debug = 0; int factorial[] = {1, 1, 2, 6, 24, 120, 720}; int N,M,K; vector<vector<int> > sets; vector<int> color; vector<int> place; vector<vector<int> > graph; /*vector<int> gen(vector<int> a, int i, int j){ P("gen"<< i << " " << j<<" "<<factorial[a.size()-1]); if(j == 1) return {a[i]}; //int j = a.size(); vector<int> res(j); res[0] = i/factorial[a.size()-1]; int ggggg = a[res[0]]; int ff = 0; FR(k, 0, a.size()-1){ if(k == res[0]) ff++; a[k] = a[k+ff]; H(a[k]); } a.pop_back(); vector<int> v = gen(a, i%factorial[a.size()], j-1); F(k, j-1){ res[k+1] = v[k]; } res[0] = ggggg; return res; } int ptoint(vector<int> v){ int res = 0; for(int i = 0; i<v.size(); i++){ res += (v[i]+1)*factorial[K-i+1]; } return res; }*/ vector<int> colortocolor(int c1, int c2, vector<int> base, vector<int>& res){ //vector<int> res(sets[c2].size(), 0); for(int u : sets[c1]){ for(int v : graph[u]) if(color[v] == c2){ res[v] += base[u]; } } return res; } string bin(int a){ string s; for(int i = 0; i<6; i++){ s+='0' + ((a & (1<<i))>>i); } return s; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>N>>M>>K; sets.resize(K); color.resize(N); graph.resize(N); place.resize(N); F(i, N){ int a; cin>>a; a--; place[i] = sets[a].size(); color[i]=a; sets[a].push_back(i); } F(i, M){ int a, b; cin>>a>>b; a--; b--; graph[a].push_back(b); graph[b].push_back(a); } P("DDDDDD"); vector<vector<int> > dp(N, vector<int>(1<<K, 0)); P("CCCCCC"); F(i, N){ dp[i][1<<color[i]] = 1; } P("BBBBBBBb"); FR(bs, 1, (1<<K)){ F(j, N) if(((1<<color[j])&bs)!=0){ for(int k : graph[j]) if(((1<<color[k])&bs)!=0){ P(bin(bs) <<" "<< j <<" "<< k<< " "<< bin(bs-(1<<color[k]))); dp[j][bs] += dp[k][bs-(1<<color[j])]; P(dp[j][bs]); } } } P("AAAAAAAAAAA"); int sum = 0;// F(i, N) F(j, 1<<K){ P(i<<" "<<bin(j)<<": "<<dp[i][j]); sum+=dp[i][j]; } cout<<sum-N; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...