제출 #50751

#제출 시각아이디문제언어결과실행 시간메모리
50751Just_Solve_The_Problem친구 (IOI14_friend)C++11
0 / 100
13 ms6684 KiB
#include <bits/stdc++.h> #include "friend.h" using namespace std; #define pb push_back #define sz(s) (int)s.size() const int N = (int)1e5 + 7; const int smN = (int)1e3 + 7; vector < int > gr[N]; int has[smN][smN]; int c[N], used[N], col; void addedge(int a, int b) { gr[a].pb(b); gr[b].pb(a); has[a][b] = has[b][a] = 1; } int res = 0; void dfs(int v, int pr, bool fl) { if (fl) { res += c[v]; } for (int to : gr[v]) { if (to == pr) continue; dfs(to, v, fl ^ 1); } } void paint(int v, int pr) { used[v] = col; for (int to : gr[v]) { if (to == pr) continue; paint(to, v); } } int findSample(int n, int confidence[], int host[], int protocol[]){ for (int i = 0; i < n; i++) c[i] = confidence[i]; int ans = 0; for (int i = 1; i < n; i++) { if (protocol[i] == 0 || protocol[i] == 2) { addedge(host[i], i); } if (protocol[i] == 1 || protocol[i] == 2) { for (int to : gr[host[i]]) { addedge(to, i); } } } col = 0; for (int i = 0; i < n; i++) { if (!used[i]) { col++; paint(i, i); } } vector < int > vec(col, 0); for (int i = 0; i < n; i++) { res = 0; dfs(i, i, 1); vec[used[i]] = max(vec[used[i]], res); } for (int to : vec) { ans += to; } 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...