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
#include
#include
using namespace std; const int maxn=5555; const int INF = 2e9; vector
> graph[maxn]; int bfs(int S, int k) { vector
visited(maxn, false); visited[S] = true; queue
q; q.push(S); q.push(INF); int res = 0; while(!q.empty()) { int node = q.front(); q.pop(); int dist = q.front(); q.pop(); if(node != S and dist >= k) { res++; } for(int i = 0; i < (int) graph[node].size(); i++) { int neighbour = graph[node][i].first; int weight = graph[node][i].second; if(!visited[neighbour]) { visited[neighbour] = true; q.push(neighbour); q.push(min(dist, weight)); } } } return res; } int main() { ifstream cin("mootube.in"); ofstream cout("mootube.out"); int n, q; cin >> n >> q; for(int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; int k; cin >> k; graph[a].push_back(make_pair(b, k)); graph[b].push_back(make_pair(a, k)); } for(int i = 0; i < q; i++) { int a, k; cin >> k >> a; a--; cout << bfs(a, k) << endl; } return 0; }
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)