이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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, x);
}
}
void init(int n, int k) {
special = k;
for(int i = 0; i < n; i++)
adj[i].clear();
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |