# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
202432 | quocnguyen1012 | Paths (BOI18_paths) | C++14 | 486 ms | 59768 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.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 5;
const ll llinf = 1e18;
bool testbit(int x, int n)
{
return x >> n & 1;
}
int addbit(int x, int n)
{
return x + (1 << n);
}
int delbit(int x, int n)
{
return x - (1 << n);
}
int f[maxn][1 << 5];
int col[maxn];
vector<int> adj[maxn];
int N, K, M;
int solve(int u, int mask)
{
int & res = f[u][mask];
if (res != -1) return res;
res = 1;
for (int v : adj[u]){
if (testbit(mask, col[v]) == 0){
res += solve(v, addbit(mask, col[v]));
}
}
return res;
}
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("A.INP", "r")){
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
}
cin >> N >> M >> K;
for (int i = 1; i <= N; ++i){
cin >> col[i]; --col[i];
}
while (M--){
int u, v; cin >> u >> v;
adj[u].pb(v); adj[v].pb(u);
}
memset(f, -1, sizeof f);
ll res = 0;
for (int i = 1; i <= N; ++i){
res += solve(i, (1 << col[i]));
}
cout << res - 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... |