Submission #1105683

#TimeUsernameProblemLanguageResultExecution timeMemory
1105683Zero_OPPaths (BOI18_paths)C++14
100 / 100
254 ms70844 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, l, r) for(int i = (l), _r = (r); i < _r; ++i) #define FOR(i, l, r) for(int i = (l), _r = (r); i <= _r; ++i) #define ROF(i, r, l) for(int i = (r), _l = (l); i >= _l; --i) #define all(v) begin(v), end(v) #define compact(v) v.erase(unique(all(v)), end(v)) #define sz(v) (int)v.size() #define dbg(x) "[" #x " = " << (x) << "]" #define file(name) if(fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout); template<typename T> bool minimize(T& a, const T& b){ if(a > b) return a = b, true; return false; } template<typename T> bool maximize(T& a, const T& b){ if(a < b) return a = b, true; return false; } using ll = long long; using ld = long double; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T> T random_int(T l, T r){ return uniform_int_distribution<T>(l, r)(rng); } template<typename T> T random_real(T l, T r){ return uniform_real_distribution<T>(l, r)(rng); } void testcase(){ int n, m, k; cin >> n >> m >> k; vector<vector<int>> adj(n); vector<int> c(n); rep(i, 0, n) cin >> c[i], --c[i]; while(m--){ int u, v; cin >> u >> v; --u, --v; adj[u].push_back(v); adj[v].push_back(u); } vector<vector<ll>> dp(n, vector<ll>(1 << k, -1)); auto dfs = [&](auto self, int u, int mask) -> long long{ if(dp[u][mask] != -1) return dp[u][mask]; ll& cur = dp[u][mask]; cur = 0; for(int v : adj[u]){ if(mask >> c[v] & 1 ^ 1){ cur += self(self, v, mask | (1 << c[v])) + 1; } } // cout << dbg(u) << dbg(mask) << dbg(dp[u][mask]) << '\n'; return cur; }; ll ans = 0; for(int i = 0; i < n; ++i){ ans += dfs(dfs, i, (1 << c[i])); } cout << ans << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); file("task"); int T = 1; //cin >> T; while(T--) testcase(); return 0; }

Compilation message (stderr)

paths.cpp: In function 'bool minimize(T&, const T&)':
paths.cpp:16:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   16 |     if(a > b) return a = b, true; return false;
      |     ^~
paths.cpp:16:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   16 |     if(a > b) return a = b, true; return false;
      |                                   ^~~~~~
paths.cpp: In function 'bool maximize(T&, const T&)':
paths.cpp:21:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   21 |     if(a < b) return a = b, true; return false;
      |     ^~
paths.cpp:21:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   21 |     if(a < b) return a = b, true; return false;
      |                                   ^~~~~~
paths.cpp: In instantiation of 'testcase()::<lambda(auto:1, int, int)> [with auto:1 = testcase()::<lambda(auto:1, int, int)>]':
paths.cpp:67:39:   required from here
paths.cpp:55:29: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   55 |             if(mask >> c[v] & 1 ^ 1){
      |                ~~~~~~~~~~~~~^~~
paths.cpp: In function 'int main()':
paths.cpp:12:54: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define file(name) if(fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
      |                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:77:5: note: in expansion of macro 'file'
   77 |     file("task");
      |     ^~~~
paths.cpp:12:87: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define file(name) if(fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
      |                                                                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:77:5: note: in expansion of macro 'file'
   77 |     file("task");
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...