Submission #907555

#TimeUsernameProblemLanguageResultExecution timeMemory
907555sysiaStar Trek (CEOI20_startrek)C++17
8 / 100
1026 ms128588 KiB
//Sylwia Sapkowska #include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-loops") using namespace std; void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << "'" << x << "'";} void __print(const char *x) {cerr << '"' << x << '"';} void __print(const string &x) {cerr << '"' << x << '"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef LOCAL #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long typedef pair<int, int> T; const int oo = 1e18, oo2 = 1e9+7, K = 30; const int mod = 998244353; void solve(){ int n, d; cin >> n >> d; vector<T>edges; for (int i = 1; i<n; i++){ int a, b; cin >> a >> b; a--;b--; edges.emplace_back(a, b); } //[0, n-1], [n, 2n-1], ... auto ch = [&](int i, int where){ return where*n + i; }; int ans = 0; auto solve = [&](vector<T>curr){ int N = n*(d+2); vector<vector<int>>G(N); auto add_edge = [&](int a, int b){ G[a].emplace_back(b); G[b].emplace_back(a); }; for (int i = 0; i<=d; i++){ for (auto [a, b]: edges){ add_edge(ch(a, i), ch(b, i)); } } for (int i = 0; i<d; i++){ auto [a, b] = curr[i]; add_edge(ch(a, i), ch(b, i+1)); } vector dp(N, vector<int>(2)); function<void(int, int)>dfs = [&](int v, int pa){ dp[v][0] = 0; dp[v][1] = 1; //gracz 1 jest teraz w v i musi zrobic ruch, ale nie ma gdzie :p for (auto x: G[v]){ if (x == pa) continue; dfs(x, v); dp[v][0] |= dp[x][1]; //musi byc jakas wygrywajaca dp[v][1] &= (dp[x][0] == 1); //musi prowadzic do samych wygrywajacych } // debug(v, dp[v]); }; dfs(0, 0); if (dp[0][0]) { ans++; auto [a, b] = curr[0]; a++;b++; debug(a, b); } }; function<void(vector<T>)>rec = [&](vector<T>curr){ if ((int)curr.size() == d){ solve(curr); return; } for (int i = 0; i<n; i++){ for (int j = 0; j<n; j++){ curr.emplace_back(i, j); rec(curr); curr.pop_back(); } } }; rec({}); cout << ans << "\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...