# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
313326 | vitkishloh228 | 특수한 그래프 (IZhO13_specialg) | C++14 | 1093 ms | 1932 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> g(n);
for (int i = 0; i < n; ++i) {
int v1;
cin >> v1;
g[i] = v1 - 1;
}
int q;
cin >> q;
while (q--) {
int ind;
cin >> ind;
if (ind == 1) {
int a1;
cin >> a1;
a1--;
g[a1] = -1;
}
else {
int a, b;
cin >> a >> b;
--a, --b;
queue<int> q;
vector<int> d(n, 1e9);
d[a] = 0;
q.push(a);
while (!q.empty()) {
int v = q.front();
q.pop();
if (g[v] == -1) continue;
if (d[g[v]] == 1e9) {
d[g[v]] = d[v] + 1;
q.push(g[v]);
}
}
if (d[b] < 1e9) {
cout << d[b] << '\n';
}
else cout << "-1\n";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |