#include <iostream>
#include <vector>
#include <unordered_set>
#include <stack>
using namespace std;
vector<vector<int>> graph;
unordered_set<int> special_planets;
bool has_infinite_stamps;
void init(int n, int k) {
graph.resize(n);
special_planets.clear();
has_infinite_stamps = false;
for (int i = 0; i < k; i++) {
special_planets.insert(i);
}
}
int add_teleporter(int u, int v) {
graph[u].push_back(v);
stack<int> stack;
unordered_set<int> visited;
stack.push(u);
while (!stack.empty()) {
int planet = stack.top();
stack.pop();
if (special_planets.count(planet) > 0) {
has_infinite_stamps = true;
return 1;
}
visited.insert(planet);
for (int neighbor : graph[planet]) {
if (visited.count(neighbor) == 0) {
stack.push(neighbor);
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |