이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "friend.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define vi vector<int>
using namespace std;
bool find(int j, vector<vi>& g, vi& btoa, vi& vis) {
if (btoa[j] == -1) return 1;
vis[j] = 1; int di = btoa[j];
for (int e : g[di])
if (!vis[e] && find(e, g, btoa, vis)) {
btoa[e] = di;
return 1;
}
return 0;
}
int dfsMatching(vector<vi>& g, vi& btoa) {
vi vis;
for(int i = 0; i < g.size(); i++) {
vis.assign(btoa.size(), 0);
for (int j : g[i])
if (find(j, g, btoa, vis)) {
btoa[j] = i;
break;
}
}
return (int)btoa.size() - (int)count(btoa.begin(), btoa.end(), -1);
}
vi cover(vector<vi>& g, int n, int m) {
vi match(m, -1);
int res = dfsMatching(g, match);
vector<bool> lfound(n, true), seen(m);
for (int it : match)
if (it != -1)
lfound[it] = false;
vi q, cover;
for(int i = 0; i < n; i++)
if (lfound[i])
q.push_back(i);
while (!q.empty()) {
int i = q.back(); q.pop_back();
lfound[i] = 1;
for (int e : g[i]) if (!seen[e] && match[e] != -1) {
seen[e] = true;
q.push_back(match[e]);
}
}
for(int i = 0; i < n; i++)
if (!lfound[i])
cover.push_back(i);
for(int i = 0; i < m; i++)
if (seen[i])
cover.push_back(n+i);
return cover;
}
int findSample(int n,int confidence[],int host[],int protocol[]){
vector<vector<int>> g(n);
for(int i = 1; i < n; i++){
if(protocol[i] == 0){
g[host[i]].pb(i);
}
else{
for(auto t : g[host[i]])
{
g[t].pb(i);
}
}
}
return (n-(int)cover(g, n, g.size()).size());
}
컴파일 시 표준 에러 (stderr) 메시지
friend.cpp: In function 'int dfsMatching(std::vector<std::vector<int> >&, std::vector<int>&)':
friend.cpp:23:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i = 0; i < g.size(); i++) {
| ~~^~~~~~~~~~
friend.cpp: In function 'std::vector<int> cover(std::vector<std::vector<int> >&, int, int)':
friend.cpp:35:6: warning: unused variable 'res' [-Wunused-variable]
35 | int res = dfsMatching(g, match);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |