제출 #151836

#제출 시각아이디문제언어결과실행 시간메모리
151836qkxwsm친구 (IOI14_friend)C++14
35 / 100
5 ms2808 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) #define SZ(x) ((int) ((x).size())) #define ALL(x) (x).begin(), (x).end() #define MAXN 100013 typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; int N; int arr[MAXN]; int dsu[2][MAXN]; int val[MAXN]; vi edge[MAXN]; int dp[MAXN][2]; int ans; int get(int flag, int u) { return (u == dsu[flag][u] ? u : dsu[flag][u] = get(flag, dsu[flag][u])); } void merge(int flag, int u, int v) { u = get(flag, u); v = get(flag, v); dsu[flag][u] = v; return; } void solve(int u, int p) { dp[u][0] = 0; dp[u][1] = val[u]; for (int v : edge[u]) { if (v == p) continue; solve(v, u); dp[u][0] += dp[v][1]; dp[u][1] += dp[v][0]; } ckmax(dp[u][1], dp[u][0]); } int findSample(int n, int confidence[], int host[], int protocol[]) { N = n; FOR(i, 0, N) { arr[i] = confidence[i]; dsu[0][i] = i; dsu[1][i] = i; } //0 im: just a normal edge. 1 myf: they literally merge. 2 wereyourfriends: //so you somehow want to store like components and info about them. FOR(i, 0, N) { int p = host[i], qid = protocol[i]; if (qid == 1 || qid == 2) { merge(0, i, p); if (qid == 1) { int sum = arr[get(1, p)] + arr[i]; merge(1, i, p); arr[get(1, i)] = sum; } } } FOR(i, 0, N) { ckmax(val[get(0, i)], arr[i]); } FORD(i, N, 1) { int p = host[i], qid = protocol[i]; if (qid == 0) { //yeah edge[get(0, p)].PB(get(0, i)); edge[get(0, i)].PB(get(0, p)); } } FOR(i, 0, N) { if (get(0, i) == i) { solve(i, N); ans = dp[i][1]; break; } } return ans; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...