QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#671125 | #898. 二分图最大匹配 | Qingyyx | WA | 16ms | 12976kb | C++20 | 2.7kb | 2024-10-24 11:06:09 | 2024-10-24 11:06:10 |
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; }
int mat[MAXN], vis[MAXN], cur;
bool dfs(int cur) {
for (int i = head[cur]; ~i; i = e[i].nxt) {
int to = e[i].to;
if (vis[to] != cur) {
vis[to] = cur;
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) ++cur, 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", mat[i] - 1, 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: 16ms
memory: 12976kb
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:
96093 63893 0 72487 1 5283 2 69829 3 42164 4 90712 5 92014 6 59953 7 71269 8 58488 9 43951 10 20110 11 30466 12 4229 13 46522 14 59008 15 62176 16 35924 17 78013 18 4961 19 27578 20 47990 21 90601 22 9079 23 36019 24 21960 25 56983 26 38043 27 24373 28 33211 29 16929 30 59580 31 49575 32 77052 33 93...
result:
wrong answer # of Matching is differ - expected: '100000', found '96093'