제출 #492012

#제출 시각아이디문제언어결과실행 시간메모리
492012davi_bart친구 (IOI14_friend)C++14
16 / 100
6 ms7376 KiB
#include "friend.h" #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long // #define int ll #define fi first #define se second #define ld long double #define pb push_back mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // Find out best sample set<int> v[100010]; vector<bool> vis(100010, 0); vector<int> figli[100010]; void dfs(int pos, int par) { if (vis[pos]) return; vis[pos] = 1; if (par != -1) figli[par].pb(pos); for (int x : v[pos]) dfs(x, pos); } int memo[100010]; int sol(int pos) { // if (vis[pos]) return memo[pos]; // vis[pos] = 1; int ans = 0; for (int x : figli[pos]) { for (int y : figli[x]) { int k = sol(y); int o = 0; // for (int z : figli[y]) { // int u = 0; // if (v[pos].count(z) == 0) { // u = sol(z); // } else { // int l = 0; // for (int w : figli[z]) { // l += sol(w); // } // u = max(u, l); // } // o += u; // } ans += max(k, o); } } return memo[pos] = ans + 1; } void visita(int pos) { if (vis[pos]) return; vis[pos] = 1; for (int x : v[pos]) visita(x); } int findSample(int N, int confidence[], int host[], int protocol[]) { int a[3] = {0, 0, 0}; for (int i = 1; i < N; i++) { a[protocol[i]]++; } if (a[1] == N - 1) { int tot = 0; for (int i = 0; i < N; i++) tot += confidence[i]; return tot; } if (a[2] == N - 1) { int tot = 0; for (int i = 0; i < N; i++) tot = max(confidence[i], tot); return tot; } for (int i = 1; i < N; i++) { if (protocol[i] == 0 || protocol[i] == 2) { v[host[i]].insert(i); v[i].insert(host[i]); } if (protocol[i] == 1 || protocol[i] == 2) { for (int x : v[host[i]]) { v[x].insert(i); v[i].insert(x); } } } int ans = 0; for (int i = 0; i < N; i++) { if (!vis[i]) { dfs(i, -1); } } // cout << "figli 0: "; // for (int u : figli[0]) cout << u << " "; // cout << endl; fill(vis.begin(), vis.end(), 0); for (int i = 0; i < N; i++) { if (!vis[i]) { int ma = 0; for (int a : figli[i]) { ma = max(ma, sol(a)); for (int b : figli[a]) { ma = max(ma, sol(b)); for (int c : figli[b]) { ma = max(ma, sol(c)); } } } ma = max(ma, sol(i)); visita(i); // cout << i << " " << ma << endl; ans += ma; } } 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...