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>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 201010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
int dis[MAX];
vector<int> adj[MAX];
pii edges[MAX];
int ans[MAX];
int R[MAX];
int p[MAX];
vector<int> st[MAX];
int chk[MAX];
int sum[MAX];
int T[MAX];
int get_next(int v, int e) {
return edges[e].first + edges[e].second - v;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, M, Q;
cin >> N >> M >> Q;
int i, a, b;
for (i = 1; i <= M; i++) cin >> a >> b, adj[a].push_back(i), adj[b].push_back(i), edges[i] = pii(a, b);
queue<int> q;
q.push(1);
dis[1] = 1;
while (q.size()) {
int t = q.front();
q.pop();
for (auto e : adj[t]) {
int v = get_next(t, e);
if (dis[v]) continue;
dis[v] = dis[t] + 1;
q.push(v);
}
}
for (i = 1; i <= M; i++) T[i] = Q + 10;
for (i = 1; i <= Q; i++) cin >> R[i], T[R[i]] = i - 1;
vector<int> vv;
for (i = 2; i <= N; i++) vv.push_back(i);
sort(vv.begin(), vv.end(), [&](int i, int j) {return dis[i] < dis[j]; });
ans[1] = Q + 10;
for (auto v : vv) {
for (auto e : adj[v]) {
int x = get_next(v, e);
if (dis[x] == dis[v] - 1) ans[v] = max(ans[v], min(ans[x], T[e]));
}
}
for (i = 2; i <= N; i++) sum[ans[i] + 1]++;
for (i = 1; i <= Q; i++) sum[i] += sum[i - 1], cout << sum[i] << ln;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |