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 <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include <numeric>
using namespace std;
const int INF = (int)1e9 + 7;
int rad;
int n, k;
vector<vector<int>> g, ig;
vector<int> mn;
vector<int> mn2;
bool is;
void addedge(int from, int to)
{
g[from].push_back(to);
ig[to].push_back(from);
}
void init(int nn, int kk)
{
is = 0;
n = nn;
k = kk;
ig.clear();
ig.resize(n);
rad = sqrt(n) + 2;
mn.clear();
mn.resize(n, +INF);
mn2.clear();
mn2.resize(n, +INF);
}
void upd2(int a, int value)
{
if (is)
{
return;
}
if (value < mn2[a])
{
mn2[a] = value;
if (a < k && mn2[a] <= a)
{
is = 1;
return;
}
for (auto& b : ig[a])
{
upd2(b, mn2[a]);
}
}
}
void upd(int a, int value)
{
if (is)
{
return;
}
if (value < mn[a])
{
mn[a] = value;
if (a < k && mn[a] <= a)
{
is = 1;
return;
}
for (auto& b : ig[a])
{
upd(b, mn[a]);
}
}
}
int add_teleporter(int from, int to)
{
addedge(from, to);
if (to < k)
{
upd(from, to);
upd2(from, to / rad);
}
else
{
upd(from, mn[to]);
upd2(from, mn2[to]);
}
if (is)
{
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... |