QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#92934 | #898. 二分图最大匹配 | Joyslog# | RE | 0ms | 0kb | C++14 | 1.2kb | 2023-03-31 08:49:10 | 2023-03-31 08:49:12 |
Judging History
answer
#include <bits/stdc++.h>
#define pb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll read() {
ll ret = 0, w = 1; char c = getchar();
while(!isdigit(c)) {if(c == '-') w = -1; c = getchar();}
while(isdigit(c)) {ret = (ret << 1) + (ret << 3) + (c ^ 48); c = getchar();}
return ret * w;
}
char buf[50];
inline void write(ll x) {
if(x < 0) x = -x, putchar('-');
int tp = 0;
do { buf[++tp] = x % 10 + 48; x /= 10;} while(x);
while(tp) putchar(buf[tp--]);
}
const int MAX_N = 510;
int n, m, e, cnt, match[MAX_N], vis[MAX_N];
pii ans[MAX_N];
vector<int> E[MAX_N];
bool dfs(int u, int tim) {
if(vis[u] == tim) return false;
vis[u] = tim;
for(int v : E[u])
if(!match[v] || dfs(match[v], tim)) {
match[v] = u;
return true;
}
return false;
}
int main() {
n = read(), m = read(), e = read();
for(int i = 1, u, v; i <= e; i++) {
u = read() + 1, v = read() + 1;
E[u].pb(v);
}
for(int i = 1; i <= n; i++)
dfs(i, i);
for(int i = 1; i <= m; i++)
if(match[i]) ans[++cnt] = make_pair(match[i], i);
write(cnt), putchar('\n');
for(int i = 1; i <= cnt; i++) {
write(ans[i].first - 1), putchar(' ');
write(ans[i].second - 1), putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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...