QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#676250#898. 二分图最大匹配Poetry#WA 50ms9964kbC++23837b2024-10-25 20:47:062024-10-25 20:47:07

Judging History

你现在查看的是最新测评结果

  • [2024-10-25 20:47:07]
  • 评测
  • 测评结果:WA
  • 用时:50ms
  • 内存:9964kb
  • [2024-10-25 20:47:06]
  • 提交

answer

#include <bits/stdc++.h>

using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;

constexpr int N = 1E5 + 5;

int L, R, m, bel[N];
int vis[N];

std::vector<int> adj[N];

int dfs(int x, int i) {
	if (vis[x] == i) return 0;
	vis[x] = i;

	for (auto v : adj[x]) {
		if (!bel[v] || dfs(bel[v], i)) {
			bel[v] = i;
			return 1;
		}
	}

	return 0;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	std::cin >> L >> R >> m;

	for (int i = 1; i <= m; ++i) {
		int u, v;
		std::cin >> u >> v;
		++u, ++v;
		adj[u].push_back(v);
	}

	int ans = 0;
	
	for (int i = 1; i <= L; ++i) {
		ans += dfs(i, i);
	}

	std::cout << ans << "\n";

	for (int i = 1; i <= R; ++i) {
		if (bel[i]) std::cout << bel[i] - 1 << " " << i - 1 << "\n";
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 50ms
memory: 9964kb

input:

100000 100000 200000
78474 45795
32144 46392
92549 13903
73460 34144
96460 92850
56318 77066
77529 84436
76342 51542
77506 99268
76410 89381
1778 61392
43607 96135
84268 74827
14857 35966
32084 94908
19876 174
1481 94390
12423 55019
64368 92587
81295 7902
25432 46032
36293 61128
73555 84836
8418 102...

output:

100000
81714 0
99979 1
97345 2
96143 3
96879 4
92160 5
99737 6
94372 7
99934 8
58488 9
96208 10
97747 11
95577 12
95278 13
52381 14
95261 15
63175 16
35924 17
99995 18
96040 19
85970 20
83385 21
99975 22
98727 23
99896 24
49446 25
97056 26
98403 27
92270 28
97833 29
60127 30
59580 31
87783 32
94148 ...

result:

wrong answer Matching is incorrect (81714, 0)