#include "game.h"
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
using ll = long long;
using ld = long double;
using vi = vector<int>;
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n, k;
namespace sub3 {
vector<vi> adj;
stack<int> st;
int id = 0;
vi low, num;
bool eligible() { return n <= 1000; }
void init() {
adj.assign(n, {});
fore(i, 0, k - 2) { adj[i].pb(i + 1); }
}
bool dfs(int u) {
low[u] = num[u] = ++id;
st.push(u);
for (auto v : adj[u]) {
if (num[v]) {
uin(low[u], num[v]);
} else {
if (dfs(v)) {
return 1;
}
uin(low[u], low[v]);
}
}
if (low[u] == num[u]) {
int v;
vector<int> vec;
do {
v = st.top();
st.pop();
low[v] = num[v] = 1e9;
vec.pb(v);
} while (v != u);
if (vec.size() >= 2) {
for (auto x : vec) {
if (x < k) {
return 1;
}
}
}
}
return 0;
}
int add_teleporter(int u, int v) {
if (u == v) {
if (u < k) {
return 1;
}
} else {
adj[u].pb(v);
}
low = num = vi(n);
id = 0;
for0(i, n) {
if (!num[i]) {
if (dfs(i)) {
return 1;
}
}
}
return 0;
}
}
void init(int N, int K) {
n = N;
k = K;
if (sub3::eligible()) {
sub3::init();
}
}
int add_teleporter(int u, int v) {
if (n <= 1000) {
return sub3::add_teleporter(u, v);
}
}
Compilation message
game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:119:1: warning: control reaches end of non-void function [-Wreturn-type]
119 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
3 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
3 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
2 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
3 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
2 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
2 ms |
208 KB |
Output is correct |
20 |
Correct |
47 ms |
348 KB |
Output is correct |
21 |
Correct |
6 ms |
336 KB |
Output is correct |
22 |
Correct |
43 ms |
464 KB |
Output is correct |
23 |
Correct |
49 ms |
336 KB |
Output is correct |
24 |
Correct |
56 ms |
336 KB |
Output is correct |
25 |
Correct |
253 ms |
408 KB |
Output is correct |
26 |
Correct |
265 ms |
500 KB |
Output is correct |
27 |
Correct |
214 ms |
548 KB |
Output is correct |
28 |
Correct |
115 ms |
336 KB |
Output is correct |
29 |
Correct |
252 ms |
400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
3 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
2 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
2 ms |
208 KB |
Output is correct |
20 |
Correct |
47 ms |
348 KB |
Output is correct |
21 |
Correct |
6 ms |
336 KB |
Output is correct |
22 |
Correct |
43 ms |
464 KB |
Output is correct |
23 |
Correct |
49 ms |
336 KB |
Output is correct |
24 |
Correct |
56 ms |
336 KB |
Output is correct |
25 |
Correct |
253 ms |
408 KB |
Output is correct |
26 |
Correct |
265 ms |
500 KB |
Output is correct |
27 |
Correct |
214 ms |
548 KB |
Output is correct |
28 |
Correct |
115 ms |
336 KB |
Output is correct |
29 |
Correct |
252 ms |
400 KB |
Output is correct |
30 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
3 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
2 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
2 ms |
208 KB |
Output is correct |
20 |
Correct |
47 ms |
348 KB |
Output is correct |
21 |
Correct |
6 ms |
336 KB |
Output is correct |
22 |
Correct |
43 ms |
464 KB |
Output is correct |
23 |
Correct |
49 ms |
336 KB |
Output is correct |
24 |
Correct |
56 ms |
336 KB |
Output is correct |
25 |
Correct |
253 ms |
408 KB |
Output is correct |
26 |
Correct |
265 ms |
500 KB |
Output is correct |
27 |
Correct |
214 ms |
548 KB |
Output is correct |
28 |
Correct |
115 ms |
336 KB |
Output is correct |
29 |
Correct |
252 ms |
400 KB |
Output is correct |
30 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
31 |
Halted |
0 ms |
0 KB |
- |