제출 #1128172

#제출 시각아이디문제언어결과실행 시간메모리
1128172kirakosyanJobs (BOI24_jobs)C++20
11 / 100
126 ms30592 KiB
#include<algorithm> #include<iostream> #include<vector> #include<string> #include<random> #include<cmath> #include<stack> #include<map> #include <iomanip> #include <queue> #include <set> using namespace std; using ll = long long; using ull = unsigned long long; ll mod = 1e9 + 7; ll pv(ll a, ll b) { if (b == 0)return 1; ll res = (pv(a, b / 2)); if (b % 2) { return (((res * res) % mod) * (a % mod)) % mod; } else { return (res * res) % mod; } } ll gcd(ll a, ll b) { while (b) { a %= b; swap(a, b); } return a; } vector<vector<ll>>gp; vector<ll>dist, x, vis; ll dfs(ll u, ll p) { ll ape = x[u]; for (ll& v : gp[u]) { if (v != p) { ape += dfs(v, u); } } return max(0ll, ape); } void solve() { ll n, s; cin >> n >> s; gp = vector<vector<ll>>(n); vector<ll> p(n); vis = dist = x = vector<ll>(n); ll ans = 0; for (ll i = 0; i < n; i++) { cin >> x[i] >> p[i]; p[i]--; if (p[i] == -1)continue; gp[p[i]].push_back(i); } for (ll i = 0; i < n; i++) { if (p[i] == -1) { ans+=(dfs(i, -1)); } } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll _ = 1; //cin >> _; while (_--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...