Submission #732637

#TimeUsernameProblemLanguageResultExecution timeMemory
732637flappybird철도 요금 (JOI16_ho_t3)C++17
100 / 100
150 ms24104 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...