# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
562966 | 2022-05-15T20:09:24 Z | aryan12 | Amusement Park (JOI17_amusement_park) | C++17 | 0 ms | 0 KB |
#include "Ioi.h" #include <bits/stdc++.h> using namespace std; #define MAXN 10010 #define INF 1000000000 static vector<int> g[MAXN]; static vector<long long> dist(MAXN, INF); static vector<bool> vis(MAXN, false); static vector<int> parent(MAXN); static long long ans = 0; static set<int> already_taken; static int Find(int x) { if(x == parent[x]) return x; return parent[x] = Find(parent[x]); } static void Unite(int a, int b) { a = Find(a), b = Find(b); parent[a] = b; } static void dfs(int node, int par, long long val) { // cout << "node = " << node << ", val = " << val << "\n"; // cout << "ans = " << ans << "\n"; if(vis[node]) { assert(par != -1); int value = Move(par); return; } vis[node] = true; if(val == 1 && !already_taken.count(dist[node] % 60)) { long long x = dist[node] % 60; ans += (1LL << x); already_taken.insert(x); } for(int to: g[node]) { // cout << "to: " << to << "\n"; if(!vis[to]) { int value = Move(to); dfs(to, node, value); } } if(par != -1) { int value = Move(par); } } long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) { for(long long i = 0; i < N; i++) { parent[i] = i; } int cnt = 0; for(int i = 0; i < M; i++) { if(Find(A[i]) != Find(B[i])) { Unite(A[i], B[i]); g[A[i]].push_back(B[i]); g[B[i]].push_back(A[i]); cnt++; } } assert(cnt == N - 1); dist[0] = 0LL; queue<int> q; q.push(0); while(!q.empty()) { int node = q.front(); q.pop(); for(int to: g[node]) { if(dist[to] == 1e9) { dist[to] = dist[node] + 1; q.push(to); } } } dfs(P, -1, (long long)(V)); return ans; }