# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81640 | inom | Schools (IZhO13_school) | C++14 | 2073 ms | 37448 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define int long long
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define in freopen("specialg.in", "r", stdin);
#define out freopen("specialg.out", "w", stdout);
using namespace std;
/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma warning(disable : 4996)
*/
const int N = 500100;
const int INF = 1e15;
int TN = 1;
int n, m;
vector<int> g[N];
int get(int x, int y) {
int d[N], us[N];
for (int i = 1; i <= n; i++) {
d[i] = -1; us[i] = 0;
}
queue<int> q; q.push(x);
d[x] = 0; us[x] = true;
while (!q.empty()) {
int v = q.front(); q.pop();
for (auto i: g[v]) {
if (!us[i]) {
d[i] = d[v] + 1;
us[i] = true; q.push(i);
}
}
}
return d[y];
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
int x; cin >> x;
if (!x) {
continue;
}
g[i].pb(x);
}
cin >> m;
while (m--) {
int t;
cin >> t;
if (t == 1) {
int x; cin >> x;
g[x].clear();
}
else {
int x, y; cin >> x >> y;
cout << get(x, y) << "\n";
}
}
return;
}
signed main() {
// ios_base::sync_with_stdio(0);
// in; out; // cin >> TN;
while (TN--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |