problemscpp
A collection of my answers to algorithm problems in c++.
载入中...
搜索中...
未找到
acwing::acwing861 命名空间参考

  1. 二分图的最大匹配
更多...

函数

bool find (vector< unordered_set< int > > &g, int x, vector< bool > &st, vector< int > &match)
 
int main (istream &cin, ostream &cout)
 
 TEST (acwing859, case1)
 

详细描述

  1. 二分图的最大匹配

函数说明

◆ find()

bool acwing::acwing861::find ( vector< unordered_set< int > > & g,
int x,
vector< bool > & st,
vector< int > & match )

在文件 acwing.cpp7522 行定义.

7522 {
7523 for(const auto y: g[x]) {
7524 if(!st[y]) {
7525 st[y] = true;
7526 if(match[y] == 0 || find(g, match[y], st, match)) {
7527 match[y] = x;
7528 return true;
7529 }
7530 }
7531 }
7532 return false;
7533 }
bool find(vector< unordered_set< int > > &g, int x, vector< bool > &st, vector< int > &match)

引用了 find().

被这些函数引用 find() , 以及 main().

◆ main()

int acwing::acwing861::main ( istream & cin,
ostream & cout )

在文件 acwing.cpp7497 行定义.

7497 {
7498 int n1;
7499 int n2;
7500 int m;
7501 cin >> n1 >> n2 >> m;
7502 int ans = 0;
7503 vector<unordered_set<int>> g(n1 + 1);
7504 vector match(n2 + 1, 0);
7505 vector st(n2 + 1, false);
7506 for(int i = 0; i < m; i++) {
7507 int u;
7508 int v;
7509 cin >> u >> v;
7510 g[u].insert(v);
7511 }
7512 for(int i = 1; i <= n1; i++) {
7513 st = vector(n2 + 1, false);
7514 if(find(g, i, st, match)) {
7515 ans++;
7516 }
7517 }
7518 cout << ans;
7519 return 0;
7520 }
vector< vector< int > > ans

引用了 find().

被这些函数引用 TEST().

◆ TEST()

acwing::acwing861::TEST ( acwing859 ,
case1  )

在文件 acwing_test.cpp3607 行定义.

3607 {
3608 istringstream in("2 2 4\n"
3609 "1 1\n"
3610 "1 2\n"
3611 "2 1\n"
3612 "2 2");
3613 auto out = ostringstream();
3614 main(in, out);
3615 const auto ans = out.str();
3616 ASSERT_EQ("2", ans);
3617 }
int main(istream &cin, ostream &cout)

引用了 main().