Submission #857162

#TimeUsernameProblemLanguageResultExecution timeMemory
857162ntkphongFriend (IOI14_friend)C++14
23 / 100
2 ms604 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; const int MAXSIZE = 1e5 + 10; vector<vector<int>> g; vector<int> vis, col; vector<int> match; void dfs(int u, vector<int> &L, vector<int> &R) { vis[u] = 1; if(!col[u]) L.push_back(u); else R.push_back(u); for(int v : g[u]) { if(vis[v]) continue ; col[v] = col[u] ^ 1; dfs(v, L, R); } } int DFS(int u) { if(vis[u]) return 0; vis[u] = 1; for(int v : g[u]) { if(match[v] == -1 || DFS(match[v])) { match[v] = u; return 1; } } return 0; } int sub(int n) { vis.resize(n); col.resize(n); match.resize(n); for(int i = 0; i < n; i ++) { vis[i] = 0; col[i] = 0; } int total = 0; for(int i = 0; i < n; i ++) { if(vis[i]) continue ; vector<int> L, R; dfs(i, L, R); for(int x : R) match[x] = -1; for(int x : L) { for(int y : L) { vis[y] = 0; } DFS(x); } for(int x : R) total += match[x] != -1; } return n - total; } int findSample(int n, int confidence[], int host[], int protocol[]){ g.resize(n); for(int i = 1; i < n; i ++) { int p = host[i]; if(protocol[i] == 0 || protocol[i] == 2) { g[i].push_back(p); g[p].push_back(i); } if(protocol[i] == 1 || protocol[i] == 2) { for(int v : g[p]) { g[i].push_back(v); g[v].push_back(i); } } } return sub(n); }
#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...