제출 #805704

#제출 시각아이디문제언어결과실행 시간메모리
805704IvanJ친구 (IOI14_friend)C++17
100 / 100
22 ms3444 KiB
#include "friend.h" #include<bits/stdc++.h> #define pb push_back #define x first #define y second #define all(a) (a).begin(), (a).end() using namespace std; typedef long long ll; typedef pair<int, int> ii; const int maxn = 1e5 + 5; int n; int c[maxn]; int par[maxn]; int find(int x) {return (x == par[x]) ? x : par[x] = find(par[x]);} void merge(int x, int y, int type) { x = find(x), y = find(y); if(type == 1) c[x] += c[y]; if(type == 2) c[x] = max(c[x], c[y]); par[y] = x; } int findSample(int n, int confidence[],int host[],int protocol[]) { for(int i = 0;i < n;i++) par[i] = i, c[i] = confidence[i]; int sum = 0; for(int i = n - 1;i > 0;i--) { if(protocol[i] == 0) { sum += c[i]; int x = find(host[i]); c[x] = max(c[x] - c[i], 0); } else merge(host[i], i, protocol[i]); } return sum + c[find(0)]; }
#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...