#include<bits/stdc++.h>
using namespace std;
const int maxn=300000+10;
int fk=0,fn=0;
vector<int>adj[maxn];
int cnt[maxn],w[maxn],vis[maxn];
void init(int n, int k) {
for(int i=0;i<k-1;i++){
adj[i].push_back(i+1);
}
fk=k;
fn=n;
}
int f=0,sz=0;
deque<int>vec;
void aval(int u){
vis[u]=1;
for(auto x:adj[u]){
if(vis[x]==0){
aval(x);
}
}
vec.push_back(u);
}
void dovom(int u){
vis[u]=1;
w[u]=sz;
cnt[sz]++;
for(auto x:adj[u]){
if(vis[x]==0){
dovom(x);
}
}
}
int add_teleporter(int u, int v) {
adj[u].push_back(v);
if(f==1||(u<fk&&v==u)){
f=1;
return 1;
}
for(int i=0;i<=sz;i++){
cnt[i]=0;
}
for(int i=0;i<fn;i++){
vis[i]=w[i]=0;
}
vec.clear();
for(int i=0;i<fn;i++){
if(vis[i]==0){
aval(i);
}
}
for(int i=0;i<fn;i++){
vis[i]=0;
}
sz=0;
while((int)vec.size()>0){
int x=vec.front();
vec.pop_front();
if(vis[x]==0){
sz++;
dovom(x);
}
}
for(int i=0;i<fk;i++){
if(cnt[w[i]]>1){
f=1;
}
}
if(f){
return 1;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7248 KB |
Output is correct |
2 |
Correct |
4 ms |
7248 KB |
Output is correct |
3 |
Correct |
5 ms |
7248 KB |
Output is correct |
4 |
Correct |
4 ms |
7248 KB |
Output is correct |
5 |
Correct |
5 ms |
7248 KB |
Output is correct |
6 |
Correct |
4 ms |
7376 KB |
Output is correct |
7 |
Correct |
4 ms |
7248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7248 KB |
Output is correct |
2 |
Correct |
4 ms |
7248 KB |
Output is correct |
3 |
Correct |
5 ms |
7248 KB |
Output is correct |
4 |
Correct |
4 ms |
7248 KB |
Output is correct |
5 |
Correct |
5 ms |
7248 KB |
Output is correct |
6 |
Correct |
4 ms |
7376 KB |
Output is correct |
7 |
Correct |
4 ms |
7248 KB |
Output is correct |
8 |
Correct |
4 ms |
7248 KB |
Output is correct |
9 |
Correct |
4 ms |
7248 KB |
Output is correct |
10 |
Correct |
4 ms |
7248 KB |
Output is correct |
11 |
Correct |
4 ms |
7248 KB |
Output is correct |
12 |
Correct |
4 ms |
7248 KB |
Output is correct |
13 |
Correct |
4 ms |
7248 KB |
Output is correct |
14 |
Correct |
4 ms |
7376 KB |
Output is correct |
15 |
Correct |
5 ms |
7248 KB |
Output is correct |
16 |
Correct |
4 ms |
7248 KB |
Output is correct |
17 |
Correct |
4 ms |
7248 KB |
Output is correct |
18 |
Correct |
4 ms |
7248 KB |
Output is correct |
19 |
Correct |
4 ms |
7248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7248 KB |
Output is correct |
2 |
Correct |
4 ms |
7248 KB |
Output is correct |
3 |
Correct |
5 ms |
7248 KB |
Output is correct |
4 |
Correct |
4 ms |
7248 KB |
Output is correct |
5 |
Correct |
5 ms |
7248 KB |
Output is correct |
6 |
Correct |
4 ms |
7376 KB |
Output is correct |
7 |
Correct |
4 ms |
7248 KB |
Output is correct |
8 |
Correct |
4 ms |
7248 KB |
Output is correct |
9 |
Correct |
4 ms |
7248 KB |
Output is correct |
10 |
Correct |
4 ms |
7248 KB |
Output is correct |
11 |
Correct |
4 ms |
7248 KB |
Output is correct |
12 |
Correct |
4 ms |
7248 KB |
Output is correct |
13 |
Correct |
4 ms |
7248 KB |
Output is correct |
14 |
Correct |
4 ms |
7376 KB |
Output is correct |
15 |
Correct |
5 ms |
7248 KB |
Output is correct |
16 |
Correct |
4 ms |
7248 KB |
Output is correct |
17 |
Correct |
4 ms |
7248 KB |
Output is correct |
18 |
Correct |
4 ms |
7248 KB |
Output is correct |
19 |
Correct |
4 ms |
7248 KB |
Output is correct |
20 |
Correct |
26 ms |
7376 KB |
Output is correct |
21 |
Correct |
6 ms |
7376 KB |
Output is correct |
22 |
Correct |
23 ms |
7400 KB |
Output is correct |
23 |
Correct |
29 ms |
7376 KB |
Output is correct |
24 |
Correct |
23 ms |
7376 KB |
Output is correct |
25 |
Correct |
119 ms |
7408 KB |
Output is correct |
26 |
Correct |
163 ms |
7412 KB |
Output is correct |
27 |
Correct |
123 ms |
7376 KB |
Output is correct |
28 |
Correct |
52 ms |
7376 KB |
Output is correct |
29 |
Correct |
107 ms |
7420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7248 KB |
Output is correct |
2 |
Correct |
4 ms |
7248 KB |
Output is correct |
3 |
Correct |
5 ms |
7248 KB |
Output is correct |
4 |
Correct |
4 ms |
7248 KB |
Output is correct |
5 |
Correct |
5 ms |
7248 KB |
Output is correct |
6 |
Correct |
4 ms |
7376 KB |
Output is correct |
7 |
Correct |
4 ms |
7248 KB |
Output is correct |
8 |
Correct |
4 ms |
7248 KB |
Output is correct |
9 |
Correct |
4 ms |
7248 KB |
Output is correct |
10 |
Correct |
4 ms |
7248 KB |
Output is correct |
11 |
Correct |
4 ms |
7248 KB |
Output is correct |
12 |
Correct |
4 ms |
7248 KB |
Output is correct |
13 |
Correct |
4 ms |
7248 KB |
Output is correct |
14 |
Correct |
4 ms |
7376 KB |
Output is correct |
15 |
Correct |
5 ms |
7248 KB |
Output is correct |
16 |
Correct |
4 ms |
7248 KB |
Output is correct |
17 |
Correct |
4 ms |
7248 KB |
Output is correct |
18 |
Correct |
4 ms |
7248 KB |
Output is correct |
19 |
Correct |
4 ms |
7248 KB |
Output is correct |
20 |
Correct |
26 ms |
7376 KB |
Output is correct |
21 |
Correct |
6 ms |
7376 KB |
Output is correct |
22 |
Correct |
23 ms |
7400 KB |
Output is correct |
23 |
Correct |
29 ms |
7376 KB |
Output is correct |
24 |
Correct |
23 ms |
7376 KB |
Output is correct |
25 |
Correct |
119 ms |
7408 KB |
Output is correct |
26 |
Correct |
163 ms |
7412 KB |
Output is correct |
27 |
Correct |
123 ms |
7376 KB |
Output is correct |
28 |
Correct |
52 ms |
7376 KB |
Output is correct |
29 |
Correct |
107 ms |
7420 KB |
Output is correct |
30 |
Execution timed out |
4078 ms |
7972 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7248 KB |
Output is correct |
2 |
Correct |
4 ms |
7248 KB |
Output is correct |
3 |
Correct |
5 ms |
7248 KB |
Output is correct |
4 |
Correct |
4 ms |
7248 KB |
Output is correct |
5 |
Correct |
5 ms |
7248 KB |
Output is correct |
6 |
Correct |
4 ms |
7376 KB |
Output is correct |
7 |
Correct |
4 ms |
7248 KB |
Output is correct |
8 |
Correct |
4 ms |
7248 KB |
Output is correct |
9 |
Correct |
4 ms |
7248 KB |
Output is correct |
10 |
Correct |
4 ms |
7248 KB |
Output is correct |
11 |
Correct |
4 ms |
7248 KB |
Output is correct |
12 |
Correct |
4 ms |
7248 KB |
Output is correct |
13 |
Correct |
4 ms |
7248 KB |
Output is correct |
14 |
Correct |
4 ms |
7376 KB |
Output is correct |
15 |
Correct |
5 ms |
7248 KB |
Output is correct |
16 |
Correct |
4 ms |
7248 KB |
Output is correct |
17 |
Correct |
4 ms |
7248 KB |
Output is correct |
18 |
Correct |
4 ms |
7248 KB |
Output is correct |
19 |
Correct |
4 ms |
7248 KB |
Output is correct |
20 |
Correct |
26 ms |
7376 KB |
Output is correct |
21 |
Correct |
6 ms |
7376 KB |
Output is correct |
22 |
Correct |
23 ms |
7400 KB |
Output is correct |
23 |
Correct |
29 ms |
7376 KB |
Output is correct |
24 |
Correct |
23 ms |
7376 KB |
Output is correct |
25 |
Correct |
119 ms |
7408 KB |
Output is correct |
26 |
Correct |
163 ms |
7412 KB |
Output is correct |
27 |
Correct |
123 ms |
7376 KB |
Output is correct |
28 |
Correct |
52 ms |
7376 KB |
Output is correct |
29 |
Correct |
107 ms |
7420 KB |
Output is correct |
30 |
Execution timed out |
4078 ms |
7972 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |