This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
vector<int> g[N];
int max_n, max_k;
int vis[N];
int cnt = 0;
void init(int n, int k)
{
max_n = n, max_k = k;
for(int i = 0; i <= k - 2; i++)
{
g[i].push_back(i + 1);
}
}
bool dfsCycle(int node)
{
vis[node] = 1;
cnt += (node <= max_k - 1);
for(int to: g[node])
{
if(vis[to] == 1)
{
if(cnt != 0) return true;
continue;
}
if(vis[to] == 2) continue;
if(dfsCycle(to)) return true;
}
vis[node] = 2;
cnt -= (node <= max_k - 1);
return false;
}
int add_teleporter(int u, int v)
{
cnt = 0;
g[u].push_back(v);
for(int i = 0; i <= max_n; i++)
{
vis[i] = 0;
}
for(int i = 0; i <= max_n; i++)
{
if(vis[i] == 0)
{
if(dfsCycle(i))
{
return 1;
}
}
}
return 0;
}
# | 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... |