QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#671119 | #898. 二分图最大匹配 | Qingyyx | WA | 191ms | 15604kb | C++20 | 2.8kb | 2024-10-24 11:04:00 | 2024-10-24 11:04:01 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define enl putchar('\n')
#define all(x) (x).begin(),(x).end()
#define debug(x) printf(" "#x":%d\n",x);
using namespace std;
const int MAXN = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
typedef pair<int, int> pii;
char buf[1 << 21], * p1 = buf, * p2 = buf, obuf[1 << 21], * o = obuf, of[35];
#define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline ll qpow(ll a, ll n) { ll res = 1; while (n) { if (n & 1)res = res * a % mod; n >>= 1; a = a * a % mod; }return res; }
template <class T = int>inline T read() { T s = 0, f = 1; char c = gc(); for (; !isdigit(c); c = gc())if (c == '-')f = -1; for (; isdigit(c); c = gc())s = s * 10 + c - '0'; return s * f; }
inline void read(int* a, int n) { for (int i = 1; i <= n; ++i)a[i] = read(); }
inline int inal(char* s) { int n = 0; for (s[0] = gc(); !isalpha(s[0]); s[0] = gc()); for (; isalpha(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline int indi(char* s) { int n = 0; for (s[0] = gc(); !isdigit(s[0]); s[0] = gc()); for (; isdigit(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline void outd(auto* a, int n) { for (int i = 1; i <= n; ++i)printf("%d ", a[i]); enl; }
int n, m, q;
int L, R;
struct EG {
int to, nxt;
}e[MAXN << 1];
int head[MAXN], etot;
inline void add(int u, int v) {
e[etot] = EG {v, head[u]};
head[u] = etot++;
}
void clear(int n = MAXN - 1) { memset(head + 1, -1, sizeof(int) * n); etot = 0; }
bool vis[MAXN];
int mat[MAXN];
bool dfs(int cur) {
for (int i = head[cur]; ~i; i = e[i].nxt) {
int to = e[i].to;
if (!vis[to]) {
vis[to] = 1;
if (mat[to] == 0 || dfs(mat[to])) {
mat[to] = cur;
return 1;
}
}
}
return 0;
}
void solve() {
L = read(), R = read(), m = read();
clear(max(L, R));
for (int i = 1; i <= m; ++i) {
int u = read() + 1, v = read() + 1;
add(u, v);
}
int cnt = 0;
for (int i = 1; i <= L; ++i) {
memset(vis + 1, 0, sizeof(bool) * R);
dfs(i);
}
for (int i = 1; i <= R; ++i)cnt += (mat[i] != 0);
printf("%d\n", cnt);
for (int i = 1; i <= R; ++i)
if (mat[i])printf("%d %d\n", i - 1, mat[i] - 1);
}
signed main(signed argc, char const* argv[]) {
clock_t c1 = clock();
#ifdef LOCAL
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
//=============================================================
int TxT = 1;
// TxT = read();
while (TxT--)
solve();
//=============================================================
#ifdef LOCAL
end :
cerr << "Time Used:" << clock() - c1 << "ms" << endl;
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 191ms
memory: 15604kb
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 0 63893 1 88633 2 96752 3 85610 4 94676 5 76685 6 31448 7 72044 8 70240 9 47175 10 43951 11 20110 12 30466 13 4229 14 46522 15 75223 16 62176 17 26851 18 78013 19 4961 20 85970 21 83385 22 99925 23 9079 24 99774 25 49446 26 97056 27 50528 28 24373 29 33211 30 47321 31 59580 32 78298 33 4755 3...
result:
wrong answer Matching is incorrect (0, 63893)