QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#341726 | #898. 二分图最大匹配 | MiniLong# | RE | 0ms | 0kb | C++14 | 3.9kb | 2024-02-29 20:49:33 | 2024-02-29 20:49:34 |
answer
#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
char ibuf[50007],*p1 = ibuf, *p2 = ibuf;
#ifdef ONLINE_JUDGE
#define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 50007, stdin), p1 == p2) ? EOF : *p1++
#else
#define get() getchar()
#endif
template<typename T> inline void read(T &t){
T x = 0, f = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
t = x * f;
}
template<typename T, typename ... Args> inline void read(T &t, Args&... args){
read(t);
read(args...);
}
template<typename T> void write(T t){
if(t < 0) putchar('-'), t = -t;
if(t >= 10) write(t / 10);
putchar(t % 10 + '0');
}
template<typename T, typename ... Args> void write(T t, Args... args){
write(t), putchar(' '), write(args...);
}
template<typename T> void writeln(T t){
write(t);
puts("");
}
template<typename T> void writes(T t){
write(t), putchar(' ');
}
#undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
const ll mod = 998244353;
ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
void add(ll &x, ll y){x = (x + y) % mod;}
void mul(ll &x, ll y){x = x * y % mod;}
ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 1e5 + 5;
const ll inf = 1e18;
int n, s, t;
int ecnt = 1, head[N];
struct edge{
ll v, w, nxt;
}e[N];
void add(int u, int v, int w){
e[++ecnt] = edge{v, w, head[u]}, head[u] = ecnt;
e[++ecnt] = edge{u, 0, head[v]}, head[v] = ecnt;
}
int cur[N], dis[N];
bool bfs(int s, int t){
mst(dis, 0);
queue<int> q; q.push(s), dis[s] = 1, cur[s] = head[s];
while(q.size()){
int u = q.front(); q.pop();
_rev(i, u){
int v = e[i].v;
if(!dis[v] && e[i].w){
dis[v] = dis[u] + 1;
cur[v] = head[v];
q.push(v);
}
}
}
return dis[t];
}
ll dfs(int u, ll in){
if(u == t) return in;
ll out = 0;
for(int i = cur[u]; i && in; i = e[i].nxt){
int v = e[i].v;
cur[u] = i;
if(e[i].w && dis[v] == dis[u] + 1){
ll d = dfs(v, min(in, e[i].w));
e[i].w -= d, e[i ^ 1].w += d;
in -= d, out += d;
}
}
if(!out) dis[u] = 0;
return out;
}
ll Dinic(){
ll flow = 0;
while(bfs(s, t)) flow += dfs(s, inf);
return flow;
}
int L, R, m;
int main(){
read(L, R, m);
s = 0, t = L + R + 1;
_rep(i, 1, m){
int u, v; read(u, v);
u++, v++;
add(u, v + L, 1);
}
_rep(i, 1, L) add(s, i, 1); _rep(i, L + 1, L + R) add(i, t, 1);
writeln(Dinic());
_rep(i, 1, L){
int u = i, v = 0;
_rev(j, i){
if(e[j ^ 1].w && e[j].v > L){
v = e[j].v - L;
}
}
if(!v) continue;
write(u - 1, v - 1), puts("");
}
return 0;
}
详细
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...