QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671196#898. 二分图最大匹配QingyyxWA 129ms15484kbC++203.0kb2024-10-24 11:33:582024-10-24 11:33:59

Judging History

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

  • [2024-10-24 11:33:59]
  • 评测
  • 测评结果:WA
  • 用时:129ms
  • 内存:15484kb
  • [2024-10-24 11:33:58]
  • 提交

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;

vector<int>E[MAXN];
int px[MAXN], py[MAXN];
int pre[MAXN], vis[MAXN], TC;
void aug(int x) {
    while (x) {
        int tmp = px[pre[x]];
        px[pre[x]] = x;
        py[x] = pre[x];
        x = tmp;
    }
}
bool bfs(int x) {
    vector<int>vec;
    queue<int>que;
    que.push(x);
    while (!que.empty()) {
        int u = que.front();
        que.pop();
        for (int v : E[x]) {
            if (vis[v] == TC)continue;
            vis[v] = TC;
            pre[v] = u;
            vec.push_back(v);
            if (!py[v]) {
                aug(v);
                for (auto x : vec) pre[x] = 0;
                return 1;
            } else {
                que.push(py[v]);
            }
        }
    }
    for (auto x : vec) pre[x] = 0;
    return 0;
}
random_device rd;
void solve() {
    L = read(), R = read(), m = read();
    for (int i = 1; i <= m; ++i) {
        int u = read() + 1, v = read() + 1;
        E[u].push_back(v);
    }
    for (int i = 1; i <= L; ++i) {
        shuffle(E[i].begin(), E[i].end(), rd);
    }
    int ans = 0;
    for (int i = 1; i <= L; i++) {
        ++TC;
        ans += bfs(i);
    }
    printf("%d\n", ans);
    for (int i = 1; i <= L; ++i)
        if (px[i])printf("%d %d\n", i - 1, px[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: 129ms
memory: 15484kb

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:

87673
0 49364
1 26066
2 89637
3 59700
4 68505
5 28330
6 38417
7 34703
8 68817
9 2599
10 90437
11 69580
12 53920
13 62095
14 99163
15 87183
16 12858
17 2814
18 64564
19 75228
20 4206
21 97167
22 60611
23 36775
24 87244
25 33291
26 17629
27 42953
28 71467
29 89214
30 48329
31 83162
32 46298
33 50041
3...

result:

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