# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1009239 | lrancic | Special graph (IZhO13_specialg) | C++17 | 1014 ms | 5648 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <unordered_set>
int path(std::vector<int> &vec) {
int x, y, c = 0; std::cin >> x >> y;
std::unordered_set<int> visited;
while (x != y) {
x = vec[x];
if (visited.find(x) != visited.end() || x == -1) return -1;
visited.insert(x);
c++;
}
return c;
}
int main() {
std::ios_base::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
int n; std::cin >> n;
std::vector<int> vec(n+1); for (int i = 1; i <= n; i++) std::cin >> vec[i];
int m; std::cin >> m;
for (int i = 0; i < m; i++) {
int act; std::cin >> act;
if (act == 1) {
int x; std::cin >> x;
vec[x] = -1;
continue;
}
std::cout << path(vec) << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |