Submission #1065358

#TimeUsernameProblemLanguageResultExecution timeMemory
1065358Mr_HusanboyFriend (IOI14_friend)C++17
0 / 100
1 ms604 KiB
#include "friend.h" #include<vector> #include <algorithm> #include <iostream> #include "assert.h" using namespace std; // Find out best sample vector<vector<int>> g; vector<int> vis, col, mt; void paint(int i, int c){ col[i] = c; for(auto u : g[i]){ if(col[u]) {assert(col[u] == -c); continue;} paint(u, -c); } } bool kuhn(int i){ assert(col[i] == 1); if(vis[i]) return false; vis[i] = 1; for(auto u : g[i]){ if(mt[u] == -1 || kuhn(mt[u])){ mt[u] = i; return true; } } return false; } int findSample(int n,int confidence[],int host[],int protocol[]){ g.resize(n); col.resize(n); mt.assign(n, -1); for(int i = 1; i < n; i ++){ if(protocol[i] == 0){ g[host[i]].push_back(i); g[i].push_back(host[i]); } if(protocol[i] == 1){ for(auto u : g[host[i]]){ g[u].push_back(i); g[i].push_back(u); } } } for(int i = 0; i < n; i ++){ if(col[i]) paint(i, 1); } for(int i = 0; i < n; i ++){ if(col[i] == -1) continue; for(auto u : g[i]){ if(mt[u] == -1){ mt[u] = i; break; } } } for(int i = 0; i < n; i ++){ if(col[i] == -1) continue; vis.assign(n, 0); kuhn(i); } int ans = n; for(int i = 0; i < n; i ++){ if(mt[i] != -1) ans --; } 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...