Submission #202432

#TimeUsernameProblemLanguageResultExecution timeMemory
202432quocnguyen1012Paths (BOI18_paths)C++14
100 / 100
486 ms59768 KiB
#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)

paths.cpp: In function 'int main()':
paths.cpp:51:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.INP", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
paths.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.OUT", "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...