Submission #30962

#TimeUsernameProblemLanguageResultExecution timeMemory
30962kajebiiiFriend (IOI14_friend)C++14
35 / 100
3 ms6808 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; #define SZ(v) ((int)(v).size()) #define ALL(v) (v).begin(),(v).end() #define one first #define two second typedef long long ll; typedef pair<double, double> pd; typedef pair<int, int> pi; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; typedef pair<ll, pi> plp; typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli; const int INF = 0x3f2f1f0f; const ll LINF = 1ll * INF * INF * 2; const int MAX_N = 1e5 + 100; int N, Nr[MAX_N], Cnt[3]; vector<int> Ed[MAX_N]; void makeG(int ho[], int pr[]) { for(int i=1; i<N; i++) { int h = ho[i]; if(pr[i] >= 1) for(int x : Ed[h]) Ed[x].push_back(i), Ed[i].push_back(x); if(pr[i] % 2 == 0) Ed[h].push_back(i), Ed[i].push_back(h); } } int Dy[MAX_N][2]; bool Vis[MAX_N]; void getDy(int v, int p) { Vis[v] = true; Dy[v][1] = Nr[v]; for(int w : Ed[v]) if(w != p) { getDy(w, v); Dy[v][0] += max(Dy[w][0], Dy[w][1]); Dy[v][1] += Dy[w][0]; } } int findSample(int n_, int nr_[], int ho_[], int pr_[]) { N = n_; for(int i=0; i<N; i++) Nr[i] = nr_[i]; if(N <= 10) { // makeG(ho_, pr_); } for(int i=1; i<N; i++) Cnt[pr_[i]]++; if(Cnt[2] == N-1) { int maxV = -1; for(int i=0; i<N; i++) maxV = max(maxV, Nr[i]); return maxV; }else if(Cnt[1] == N-1) { int sum = 0; for(int i=0; i<N; i++) sum += Nr[i]; return sum; }else if(Cnt[0] == N-1) { makeG(ho_, pr_); int sum = 0; for(int i=0; i<N; i++) if(Vis[i] == false) { getDy(i, -1); sum += max(Dy[i][0], Dy[i][1]); } return sum; } return -1; }
#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...