# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
148109 | WhipppedCream | Paths (BOI18_paths) | C++17 | 481 ms | 60924 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Power Of Ninja Go
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector< ii > vii;
#define X first
#define Y second
#define pb push_back
const int maxn = 3e5+5;
int dp[maxn][33];
vi adj[maxn];
int col[maxn];
int ways(int u, int bit)
{
ll res = 1;
if(dp[u][bit] != -1) return dp[u][bit];
for(auto v : adj[u])
{
if((1<<col[v]) & bit) continue;
res += ways(v, bit | (1<<col[v]));
}
return dp[u][bit] = res;
}
int main()
{
memset(dp, -1, sizeof dp);
int n, m, k; scanf("%d %d %d", &n, &m, &k);
for(int i = 1; i<= n; i++) scanf("%d", col+i);
for(int i = 1; i<= n; i++) col[i]--;
while(m--)
{
int u, v; scanf("%d %d", &u, &v);
adj[u].pb(v); adj[v].pb(u);
}
ll ret = 0;
for(int i = 1; i<= n; i++) ret += ways(i, 1<<col[i]);
printf("%lld\n", ret-n);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |