QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#474262 | #898. 二分图最大匹配 | N_z_# | WA | 1494ms | 32372kb | C++14 | 6.0kb | 2024-07-12 16:58:24 | 2024-07-12 16:58:26 |
Judging History
answer
#if defined(LOCAL) or not defined(LUOGU)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,unroll-loops")
#endif
#include<bits/stdc++.h>
using namespace std;
struct time_helper
{
#ifdef LOCAL
clock_t time_last;
#endif
time_helper()
{
#ifdef LOCAL
time_last=clock();
#endif
}
void test()
{
#ifdef LOCAL
auto time_now=clock();
std::cerr<<"time:"<<1.*(time_now-time_last)/CLOCKS_PER_SEC<<";all_time:"<<1.*time_now/CLOCKS_PER_SEC<<std::endl;
time_last=time_now;
#endif
}
~time_helper()
{
test();
}
}time_helper;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#define Setprecision 10
#define between '\n'
#define __int128 long long
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(T x){for(auto &y:x)*this<<y<<between;*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-Setprecision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(T c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(std::string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
void solve();
main()
{
int t=1;
// cin>>t;
while(t--)solve();
}
int flow[800005],dis[200005],arc[200005];
int n,m,s,t;
vector<pair<int,int>>e[200005];
bool bfs(int s,int t)
{
for(int x=1;x<=n;x++)
dis[x]=1e9;
dis[s]=0;
queue<int>q;
q.push(s);
while(!q.empty())
{
int u=q.front();
if(u==t)return 1;
q.pop();
for(auto [v,id]:e[u])
if(flow[id]&&dis[v]>dis[u]+1)
{
dis[v]=dis[u]+1;
q.push(v);
}
}
return 0;
}
long long dfs(int u,int t,long long lim)
{
if(u==t)return lim;
long long fl=0;
for(int &x=arc[u];x<e[u].size();x++)
{
auto [v,id]=e[u][x];
if(dis[v]!=dis[u]+1||!flow[id])continue;
long long nf=dfs(v,t,min<long long>(lim,flow[id]));
flow[id]-=nf,flow[id^1]+=nf;
fl+=nf,lim-=nf;
if(lim==0)break;
}
return fl;
}
long long dinic(int s,int t)
{
long long res=0;
while(bfs(s,t))
{
for(int x=1;x<=n;x++)
arc[x]=0;
res+=dfs(s,t,1e18);
}
return res;
}
void solve()
{
int n1,n2;
cin>>n1>>n2>>m;
n=n1+n2+2;
s=n-1,t=n;
int ct=0;
vector<tuple<int,int,int>>tp;
for(int x=0;x<m;x++)
{
int u,v;
cin>>u>>v;
u++,v++;
v+=n1;
tp.emplace_back(ct,u,v);
flow[2*ct]=1;
flow[2*ct+1]=0;
e[u].emplace_back(v,2*ct);
e[v].emplace_back(u,2*ct+1);
++ct;
}
for(int x=1;x<=n1;x++)
{
int u=s,v=x;
flow[2*ct]=1;
flow[2*ct+1]=0;
e[u].emplace_back(v,2*ct);
e[v].emplace_back(u,2*ct+1);
++ct;
}
for(int x=1;x<=n2;x++)
{
int u=x+n1,v=t;
flow[2*ct]=1;
flow[2*ct+1]=0;
e[u].emplace_back(v,2*ct);
e[v].emplace_back(u,2*ct+1);
++ct;
}
cout<<dinic(s,t)<<endl;
for(auto [id,u,v]:tp)
if(flow[id^1])cout<<u-1<<' '<<v-n1-1<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1494ms
memory: 32372kb
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 78474 45795 73460 34144 96460 92850 77529 84436 77506 99268 43607 96135 14857 35966 32084 94908 12423 55019 64368 92587 25432 46032 73555 84836 12085 45676 41688 92976 4945 3241 34310 59763 29100 60189 49166 48275 23562 76094 70329 91264 2877 89679 44340 32951 39413 87026 5168 61054 42887 236...
result:
wrong answer Matching is incorrect, twice left: 12842