QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#671129 | #898. 二分图最大匹配 | Qingyyx | TL | 46ms | 15564kb | C++20 | 2.7kb | 2024-10-24 11:06:57 | 2024-10-24 11:06:57 |
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], TC;
bool dfs(int cur) {
for (int i = head[cur]; ~i; i = e[i].nxt) {
int to = e[i].to;
if (vis[to] != TC) {
vis[to] = TC;
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) ++TC, 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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 42ms
memory: 15432kb
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 63893 0 88633 1 96752 2 85610 3 94676 4 76685 5 31448 6 72044 7 70240 8 47175 9 43951 10 20110 11 30466 12 4229 13 46522 14 75223 15 62176 16 26851 17 78013 18 4961 19 85970 20 83385 21 99925 22 9079 23 99774 24 49446 25 97056 26 50528 27 24373 28 33211 29 47321 30 59580 31 78298 32 4755 33 9...
result:
ok OK
Test #2:
score: 0
Accepted
time: 46ms
memory: 15564kb
input:
100000 100000 200000 56815 52516 2576 76201 40377 1757 50463 66496 15833 50879 9828 16330 80692 9962 51095 17590 15870 35191 91301 65509 90774 57492 11890 8966 44786 41895 3386 35478 93470 47452 84803 93635 90745 34876 18201 38717 7472 34257 36580 19532 13248 27524 6441 69869 8821 61870 94536 67713 ...
output:
100000 97875 0 94264 1 74429 2 66378 3 74096 4 51747 5 18521 6 42713 7 40688 8 99131 9 51895 10 33489 11 99689 12 77565 13 47931 14 25562 15 25766 16 55887 17 2119 18 45605 19 11619 20 51396 21 81044 22 91839 23 83277 24 87787 25 9579 26 95681 27 76389 28 75933 29 50341 30 81760 31 65030 32 2286 33 ...
result:
ok OK
Test #3:
score: 0
Accepted
time: 0ms
memory: 10100kb
input:
4 4 7 1 1 2 2 0 0 3 1 1 2 2 0 3 2
output:
3 0 0 1 1 2 2
result:
ok OK
Test #4:
score: -100
Time Limit Exceeded
input:
100000 100000 199999 25370 25370 85964 85963 415 415 16796 16796 12437 12437 45409 45408 63005 63004 22155 22155 87828 87827 84013 84013 37307 37307 72324 72324 83703 83703 55390 55389 6780 6779 78090 78090 9375 9375 82192 82192 74694 74694 49841 49841 15798 15798 69855 69854 82948 82947 97389 97388...