Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
//#include
using namespace std; const int maxn = 3e5 + 10; vector
graph[maxn]; int salary[maxn]; int parent[maxn]; int n, B; int cnt; void dfs(int node) { if(node == 0) { return; } for(int i = 0; i < (int) graph[node].size(); i++) { int neighbour = graph[node][i]; if(neighbour == parent[node]) { if(salary[node] > salary[neighbour]) { cnt++; salary[neighbour] = salary[node]; dfs(neighbour); } } } } int main() { ios_base::sync_with_stdio(false); cin >> n >> B; salary[0] = B; for(int i = 1; i <= n; i++) { int r, p; cin >> salary[i] >> p; parent[i] = p; graph[i].push_back(p); graph[p].push_back(i); } for(int i = 1; i <= n; i++) { cnt = 0; dfs(i); cout << cnt << "\n"; } return 0; } /* 7 1 2 1 3 2 4 2 5 3 6 3 7 **/
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)