Submission #206894

#TimeUsernameProblemLanguageResultExecution timeMemory
206894okoPaths (BOI18_paths)C++14
100 / 100
653 ms348244 KiB
#include<bits/stdc++.h> using namespace std; const long long mod=1e9+7; long long n,m,k,a[300005],ans,dp[300005][70],vis[300005][70]; vector<int>gr[300005]; long long dfs(int x,int mask) { long long num=0; if(vis[x][mask])return dp[x][mask]; vis[x][mask]=1; for(int i=0;i<gr[x].size();i++) { int u=gr[x][i]; if((mask&(1<<a[u])))continue; num+=dfs(u,(mask|(1<<a[u]))); } return dp[x][mask]=num+1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(".in","r",stdin); //freopen(".out","w",stdout); cin>>n>>m>>k; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=0;i<m;i++) { int x,y; cin>>x>>y; gr[x].push_back(y); gr[y].push_back(x); } for(int i=1;i<=n;i++)ans+=dfs(i,(1<<a[i])); cout<<ans-n; }

Compilation message (stderr)

paths.cpp: In function 'long long int dfs(int, int)':
paths.cpp:11:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<gr[x].size();i++)
                 ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...