#include <bits/stdc++.h>
using namespace std;
using ll = int; using pii = pair<ll,ll>;
ll N,K;
const ll INF = 1e9;
vector<vector<ll>> f; //forward edges
vector<ll> mc; //min color
void init(int N1, int K1) {
N=N1; K=K1;
f.clear(); mc.clear();
vector<int> vb;
for (ll i=0;i<N;i++) {
f.push_back(vb);
mc.push_back(-INF);
}
for (ll k=0;k<K;k++){
mc[k]=k;
}
}
int add_teleporter(int u, int v) {
if (u<K && v<K) {
if (v<=u) {
return 1;
} else {
return 0;
}
}
if (u==v) {
return 0;
}
if (v<K && mc[u]<=v) {
return 1;
}
//cout << "updating u,v="<<u<<","<<v<<"\n";
f[u].push_back(v);
if (mc[u]<=mc[v]) {
return 0;
}
stack<int> s;
ll val = mc[u];
s.push(v);
while (!s.empty()) {
ll x = s.top(); s.pop();
if (x<K) {
if (x<=val) {
return 1;
}
} else {
if (mc[x]<val) {
//cout << "processD: x="<<x<<"\n";
mc[x]=val;
for (ll y: f[x]) {
s.push(y);
}
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Incorrect |
0 ms |
344 KB |
Wrong Answer[1] |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Incorrect |
0 ms |
344 KB |
Wrong Answer[1] |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Incorrect |
0 ms |
344 KB |
Wrong Answer[1] |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Incorrect |
0 ms |
344 KB |
Wrong Answer[1] |
9 |
Halted |
0 ms |
0 KB |
- |