답안 #907555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
907555 2024-01-15T20:51:16 Z sysia Star Trek (CEOI20_startrek) C++17
8 / 100
1000 ms 128588 KB
//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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Execution timed out 1026 ms 128588 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1025 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 274 ms 348 KB Output is correct
3 Correct 260 ms 492 KB Output is correct
4 Correct 231 ms 348 KB Output is correct
5 Correct 269 ms 592 KB Output is correct
6 Correct 286 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 274 ms 348 KB Output is correct
3 Correct 260 ms 492 KB Output is correct
4 Correct 231 ms 348 KB Output is correct
5 Correct 269 ms 592 KB Output is correct
6 Correct 286 ms 344 KB Output is correct
7 Execution timed out 1012 ms 952 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 274 ms 348 KB Output is correct
3 Correct 260 ms 492 KB Output is correct
4 Correct 231 ms 348 KB Output is correct
5 Correct 269 ms 592 KB Output is correct
6 Correct 286 ms 344 KB Output is correct
7 Execution timed out 1012 ms 952 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 274 ms 348 KB Output is correct
3 Correct 260 ms 492 KB Output is correct
4 Correct 231 ms 348 KB Output is correct
5 Correct 269 ms 592 KB Output is correct
6 Correct 286 ms 344 KB Output is correct
7 Execution timed out 1012 ms 952 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 274 ms 348 KB Output is correct
3 Correct 260 ms 492 KB Output is correct
4 Correct 231 ms 348 KB Output is correct
5 Correct 269 ms 592 KB Output is correct
6 Correct 286 ms 344 KB Output is correct
7 Execution timed out 1012 ms 952 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Execution timed out 1026 ms 128588 KB Time limit exceeded
3 Halted 0 ms 0 KB -