QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671097#898. 二分图最大匹配QingyyxWA 106ms12352kbC++202.8kb2024-10-24 10:52:502024-10-24 10:52:51

Judging History

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

  • [2024-10-24 10:52:51]
  • 评测
  • 测评结果:WA
  • 用时:106ms
  • 内存:12352kb
  • [2024-10-24 10:52:50]
  • 提交

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);
    }
    for (int i = 1; i <= L; ++i)
        if (!mat[i]) {
            memset(vis + 1, 0, sizeof(bool) * R);
            dfs(i);
        }
    int cnt = 0;
    for (int i = 1; i <= L; ++i)cnt += (mat[i] != 0);
    printf("%d\n", cnt);
    for (int i = 1; i <= L; ++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: 106ms
memory: 12352kb

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:

63169
0 12041
1 88633
2 5283
4 42164
6 31448
7 72044
8 70240
10 43951
11 72327
12 30466
13 60846
16 50389
18 78013
19 21527
20 27578
22 90601
23 76846
24 36019
29 25033
30 47321
31 23472
32 49575
35 78134
38 20169
42 78204
43 99703
44 14237
46 21407
47 22720
50 29822
52 94950
53 56990
54 62626
58 57...

result:

wrong answer # of Matching is differ - expected: '100000', found '63169'