Submission #1514302
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pp; typedef pair<ll,ll> pll; void read(int& x){ scanf("%d",&x); } void read(ll& x){ scanf("%lld",&x); } template<typename T,typename... Args> void read(T& a,Args&... b){ read(a); read(b...); } #define all(x) (x).begin(),(x).end() #define pb push_back #define eb emplace_back #define x first #define y second int n, k; int nxt[100010]; vector<int> edge[100010]; int dep[100010]; int par[20][100010]; int tin[100010]; int tout[100010]; int tn; int ans; priority_queue<pp> pq; void dfs(int x){ tin[x] = ++tn; for(int y:edge[x]){ dep[y]=dep[x]+1; par[0][y]=x; dfs(y); } tout[x] = tn; if(dep[x] > k) pq.emplace(dep[x], x); } int P(int x){ int df = k-1; for(int i=19; 0<=i; --i) if(1&(df>>i)) x=par[i][x]; return x; } struct SEG { const static int M = 131072; int tree[M<<1]; void mark(int x){ int l=tin[x], r=tout[x]; l+=M; r+=M; while(l<=r){ if(l%2==1) tree[l++]=1; if(r%2==0) tree[r--]=1; l>>=1; r>>=1; } } int get(int p){ for(p+=M; p; p/=2) if(tree[p]) return 1; return 0; } } seg; int main() { read(n, k); for(int i=1; i<=n; ++i){ read(nxt[i]); if(i != 1) edge[nxt[i]].pb(i); } ans = (nxt[1] != 1); dfs(1); for(int i=1; i<20; ++i) for(int j=1; j<=n; ++j) par[i][j] = par[i-1][par[i-1][j]]; while(pq.size()){ int p=pq.top().second; pq.pop(); if(seg.get(p)) continue; ++ans; seg.mark(P(p)); } printf("%d\n", ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Teleporter |
User | Namnamseo |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1565 Byte |
Status | WA |
Exec Time | 50 ms |
Memory | 21492 KB |
Compile Error
./Main.cpp: In function ‘void read(int&)’: ./Main.cpp:6:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] void read(int& x){ scanf("%d",&x); } ^ ./Main.cpp: In function ‘void read(ll&)’: ./Main.cpp:7:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] void read(ll& x){ scanf("%lld",&x); } ^
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 800 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 3 ms | 10624 KB |
0_01.txt | AC | 3 ms | 10624 KB |
0_02.txt | AC | 3 ms | 10624 KB |
1_00.txt | AC | 3 ms | 10624 KB |
1_01.txt | AC | 3 ms | 10624 KB |
1_02.txt | WA | 46 ms | 21492 KB |
1_03.txt | WA | 47 ms | 21492 KB |
1_04.txt | WA | 47 ms | 21492 KB |
1_05.txt | WA | 49 ms | 21492 KB |
1_06.txt | WA | 38 ms | 20728 KB |
1_07.txt | WA | 38 ms | 20728 KB |
1_08.txt | AC | 30 ms | 19840 KB |
1_09.txt | AC | 29 ms | 19712 KB |
1_10.txt | WA | 47 ms | 19184 KB |
1_11.txt | WA | 48 ms | 19184 KB |
1_12.txt | WA | 48 ms | 19184 KB |
1_13.txt | WA | 49 ms | 16756 KB |
1_14.txt | WA | 50 ms | 16756 KB |
1_15.txt | WA | 49 ms | 16756 KB |
1_16.txt | WA | 29 ms | 14584 KB |
1_17.txt | AC | 20 ms | 13692 KB |
1_18.txt | AC | 20 ms | 13692 KB |
1_19.txt | AC | 14 ms | 12536 KB |
1_20.txt | AC | 14 ms | 12536 KB |
1_21.txt | AC | 14 ms | 12536 KB |
1_22.txt | WA | 46 ms | 15220 KB |
1_23.txt | WA | 46 ms | 15220 KB |
1_24.txt | WA | 46 ms | 15220 KB |
1_25.txt | WA | 46 ms | 14708 KB |
1_26.txt | WA | 46 ms | 14708 KB |
1_27.txt | WA | 44 ms | 14708 KB |
1_28.txt | WA | 36 ms | 14068 KB |
1_29.txt | WA | 21 ms | 13056 KB |
1_30.txt | AC | 19 ms | 12672 KB |
1_31.txt | WA | 48 ms | 15352 KB |
1_32.txt | AC | 25 ms | 13568 KB |
1_33.txt | AC | 25 ms | 13568 KB |
1_34.txt | AC | 25 ms | 13568 KB |
1_35.txt | WA | 49 ms | 15732 KB |
1_36.txt | AC | 26 ms | 13952 KB |
1_37.txt | AC | 26 ms | 13952 KB |
1_38.txt | AC | 26 ms | 13952 KB |
1_39.txt | WA | 49 ms | 15736 KB |
1_40.txt | WA | 47 ms | 15604 KB |
1_41.txt | AC | 26 ms | 13952 KB |
1_42.txt | AC | 26 ms | 13952 KB |
1_43.txt | WA | 50 ms | 15864 KB |
1_44.txt | WA | 49 ms | 15864 KB |
1_45.txt | WA | 39 ms | 14968 KB |
1_46.txt | AC | 26 ms | 14208 KB |
1_47.txt | WA | 48 ms | 17144 KB |
1_48.txt | WA | 47 ms | 17144 KB |
1_49.txt | WA | 39 ms | 16248 KB |
1_50.txt | AC | 27 ms | 15360 KB |
1_51.txt | WA | 48 ms | 20468 KB |
1_52.txt | WA | 49 ms | 20468 KB |
1_53.txt | WA | 49 ms | 20340 KB |
1_54.txt | AC | 29 ms | 18688 KB |