#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> adj[1001];
int K,N;
void init(int32_t n, int32_t k) {
N=n;K=k;
for(int i=0;i<k-1;i++)adj[i].emplace_back(i+1);
}
vector<pair<bool,bool>> visited;
vector<int> ans;
int DFS(int x){
if(visited[x].second)return 0;
if(visited[x].first){ans.emplace_back(x);return x;}
visited[x].first=true;
for(int&i:adj[x]){
int temp = DFS(i);
if(temp==0)continue;
if(temp==-1)return -1;
ans.emplace_back(x);
if(x==temp)return -1;
return temp;
}
visited[x].first=false;
visited[x].second=true;
return 0;
}
int32_t add_teleporter(int32_t u, int32_t v) {
visited = vector<pair<bool,bool>>(N);
adj[u].emplace_back(v);
DFS(0);
return min(1,(int32_t)ans.size());
}
//namespace {
//
// int32_t read_int() {
// int32_t x;
// if (scanf("%d", &x) != 1) {
// fprintf(stderr, "Error while reading input\n");
// exit(1);
// }
// return x;
// }
//
//} // namespace
//
//int32_t main() {
// int32_t N = read_int();
// int32_t M = read_int();
// int32_t K = read_int();
// std::vector<int32_t> u(M), v(M);
// for (int32_t i = 0; i < M; ++i) {
// u[i] = read_int();
// v[i] = read_int();
// }
//
// init(N, K);
// int32_t i;
// for (i = 0; i < M; ++i) {
// int32_t answer = add_teleporter(u[i], v[i]);
// if (answer != 0 && answer != 1) {
// i = -1;
// break;
// } else if (answer == 1) {
// break;
// }
// }
// printf("%d\n", i);
// return 0;
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
356 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
356 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
356 KB |
Output is correct |
11 |
Incorrect |
1 ms |
344 KB |
Wrong Answer[1] |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
356 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
356 KB |
Output is correct |
11 |
Incorrect |
1 ms |
344 KB |
Wrong Answer[1] |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
356 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
356 KB |
Output is correct |
11 |
Incorrect |
1 ms |
344 KB |
Wrong Answer[1] |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
356 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
356 KB |
Output is correct |
11 |
Incorrect |
1 ms |
344 KB |
Wrong Answer[1] |
12 |
Halted |
0 ms |
0 KB |
- |