Submission #745273

#TimeUsernameProblemLanguageResultExecution timeMemory
745273speedyArda게임 (APIO22_game)C++17
0 / 100
215 ms262144 KiB
#include "game.h" #include "bits/stdc++.h" using namespace std; const int MAXN = 3e4+5; const int MAXK = 1e3+5; vector< vector<int> > adj(MAXN); bool visited[MAXN][MAXK]; int ans = 0; int special = 0; void dfs(int v, int x) { visited[v][x] = true; if(v <= x) // v is also a special node in this case, as we know x is special and all specials are 0, 1, 2 .... k - 1 ans = 1; // Came to smaller special node so we can go v -> x and repeat the cycle for(int e : adj[v]) { if(visited[e][x]) continue; dfs(e, v); } } void init(int n, int k) { special = k; for(int i = 0; i <= k - 2; i++) { adj[i].push_back(i + 1); } for(int i = 0; i < k - 1; i++) dfs(i + 1, i); // if we do i, i then it will trigger if(v <= x) in the dfs false. } int add_teleporter(int u, int v) { adj[u].push_back(v); for(int i = 0; i < special; i++) { if((u == i || visited[u][i]) && !visited[v][i]) dfs(v, i); } return ans; }
#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...