题目传送门:http://uoj.ac/problem/78
离线版题目:http://paste.ubuntu.com/19130171/
今天来搞一搞图论,先来一发二分图。
Dinic此题的时间还是不错的,能踩Dinic的,都只有二分图专门的算法
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int MAXN = 5000000+9; const int INF = 10000000; int n1,n2,m,s,t,vout; int T=1,to[MAXN],nxt[MAXN],head[MAXN]; int dis[MAXN],que[MAXN],fro,bak; int cap[MAXN],flow[MAXN],cur[MAXN]; inline int read(){ char c=getchar(); int buf=0,f=1; while (c<'0'||c>'9'){if(c=='-')f=-1;;c=getchar();} while (c<='9'&&c>='0'){buf=buf*10+c-'0';c=getchar();} return buf*f; } inline void AddEdge(int a, int b, int CAP){ to[++T] = b; nxt[T] = head[a]; head[a] = T; cap[T] = CAP; to[++T] = a; nxt[T] = head[b]; head[b] = T; cap[T] = 0; } inline bool BFS(){ memset(dis,-1,sizeof(dis)); que[fro=bak=1] = s; dis[s] = 0; while (bak <= fro) { int w = que[bak++]; for (int i=head[w];i;i=nxt[i]) if (flow[i] < cap[i] && dis[to[i]] == -1) dis[to[i]] = dis[w] + 1, que[++fro] = to[i]; } return dis[t] != -1; } int MaxFlow(int w, int f){ if (w == t) return f; else { int ret = 0; for (int &i=cur[w];i;i=nxt[i]){ if (flow[i] < cap[i] && dis[to[i]] == dis[w] + 1){ int tmp = MaxFlow(to[i], min(f, cap[i]-flow[i])); flow[i] += tmp; flow[i^1] -= tmp; ret += tmp; if (ret == f) return ret; } } return ret; } } inline void Dinic(){ while (BFS()){ for (int i=0;i<=t;i++) cur[i] = head[i]; vout += MaxFlow(s, INF); } } int main(){ n1=read(); n2=read(); m=read(); s = 0; t = n1 + n2 + 1; for (int i=1,a,b;i<=m;i++) a = read(), b = read(), AddEdge(a,n1+b,1); for (int i=1;i<=n1;i++) AddEdge(s,i,1); for (int i=n1+1;i<=n1+n2;i++) AddEdge(i,t,1); Dinic(); printf("%d\n",vout); for (int w=1;w<=n1;w++){ vout = 0; for (int i=head[w];i;i=nxt[i]) if (flow[i] && to[i] > n1) { vout = to[i]-n1; break; } printf("%d\n",vout); } return 0; }
Really enjoyed this article.Thanks Again.
Appreciate you sharing, great post. Cool.
I think this is a real great article post.Thanks Again. Really Cool.
Im obliged for the article.Thanks Again.
Thanks again for the blog.Really thank you! Keep writing.
Say, you got a nice post.Much thanks again. Great.
Very good blog article.Really thank you! Really Great.
I loved your article.Thanks Again. Really Cool.
I am so grateful for your blog article. Much obliged.
Looking forward to reading more. Great blog post. Want more.
I really like and appreciate your blog post.Much thanks again. Really Cool.
Awesome blog.Really thank you! Cool.
I really enjoy the article post.Really looking forward to read more. Keep writing.
Thanks for sharing, this is a fantastic blog. Much obliged.
I value the blog article.Really thank you! Want more.
Enjoyed every bit of your blog post.Thanks Again. Fantastic.
Muchos Gracias for your post.Thanks Again. Great.
Really informative blog article.Thanks Again. Cool.
I really like and appreciate your blog post. Much obliged.
Hey There. I found your blog using msn. This is a really well written article.
I’ll be sure to bookmark it and come back to read
more of your useful info. Thanks for the post. I will definitely
return.
Thanks for sharing your thoughts on coconut oil this.
Regards
Major thankies for the blog article.Thanks Again. Awesome.
Muchos Gracias for your blog article.Really thank you! Want more.
Superb post but I was wondering if you could write a litte more on this topic?
I’d be very grateful if you could elaborate a little
bit further. Appreciate it!
I cannot thank you enough for the post.Really thank you! Really Cool.
Wow, great article. Keep writing.
I will immediately seize your rss as I can not find your email subscription link or newsletter service.
Do you have any? Please permit me recognise in order that I could subscribe.
Thanks.
I really like and appreciate your post.Much thanks again. Much obliged.
Thanks so much for the blog article.Thanks Again. Awesome.
Thanks a lot for the article. Will read on…
Your means of describing everything in this
piece of writing is truly pleasant, all can simply understand it,
Thanks a lot.
I loved your blog article.Really thank you! Much obliged.
I loved your article.Thanks Again. Much obliged.
Every weekend i used to pay a quick visit this web page, for the reason that i wish for enjoyment, since this this web site conations genuinely
nice funny data too.
Thanks-a-mundo for the article post.Much thanks again. Keep writing.
Very neat article.Thanks Again. Fantastic.
For the reason that the admin of this website is working, no hesitation very quickly it will be famous,
due to its quality contents.
I really enjoy the article.Thanks Again. Really Cool.
Major thankies for the post.Thanks Again.
Very good blog article. Fantastic.
I think this is a real great blog post.Much thanks again.
A big thank you for your post.Really thank you! Really Great.
My brother suggested I may like this website.
He was totally right. This submit actually made my day. You can not believe just how a lot time I had spent for this info!
Thank you!
I truly appreciate this blog article. Really Cool.
This is one awesome blog article.Really looking forward to read more. Will read on…
Very informative blog article.Thanks Again. Much obliged.
I think this is a real great blog.Much thanks again. Awesome.
If some one wishes expert view about blogging and site-building after that i recommend him/her
to visit this website, Keep up the nice work.
I cannot thank you enough for the article post.Much thanks again. Will read on…
Say, you got a nice blog post. Really Cool.
It’s a pity you don’t have a donate button! I’d most
certainly donate to this fantastic blog! I guess for now i’ll settle for
bookmarking and adding your RSS feed to my Google account.
I look forward to brand new updates and will share this blog with my Facebook group.
Talk soon!
Looking forward to reading more. Great blog article.Really thank you!
Awesome blog. Will read on…
Good article. I’m experiencing some of these issues as well..
Thanks a lot for the blog article.Really looking forward to read more. Cool.
I am regular reader, how are you everybody? This article posted
at this site is genuinely nice.
Thanks for the post.Really thank you! Fantastic.
Major thanks for the blog post.Much thanks again. Keep writing.
Howdy! Someone in my Facebook group shared this website with
us so I came to give it a look. I’m definitely loving the information. I’m book-marking and will be
tweeting this to my followers! Terrific blog and wonderful style and design.
I am truly thankful to the owner of this web page who has shared this enormous paragraph at at this time.
Thanks for sharing, this is a fantastic blog post.Thanks Again. Want more.
Im grateful for the article.Really looking forward to read more. Great.
Looking forward to reading more. Great article.Really looking forward to read more. Really Great.
Thanks for sharing, this is a fantastic blog. Much obliged.
Thanks for sharing, this is a fantastic article post.Really thank you! Really Cool.
Fantastic post.Really thank you! Cool.
Really enjoyed this blog. Great.
We’re a gaggle of volunteers and opening a new scheme in our community.
Your site offered us with useful info to work on. You’ve done an impressive job and our
whole group might be grateful to you.
Thanks-a-mundo for the blog.Really looking forward to read more. Really Cool.
Hey, thanks for the blog. Want more.
I am often to blogging and i really appreciate your content. The article has really peaks my interest. I am going to bookmark your site and keep checking for new information.
I really enjoy the post. Fantastic.
Enjoyed every bit of your blog post.Really thank you! Fantastic.
Great blog.Much thanks again. Much obliged.
I cannot thank you enough for the article.Much thanks again. Keep writing.
Today, I went to the beach with my children. I found a
sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the
shell to her ear and screamed. There was a hermit crab
inside and it pinched her ear. She never wants to go back!
LoL I know this is completely off topic but I
had to tell someone!
Im obliged for the article post.Really thank you! Cool.
I loved your article.Really looking forward to read more. Much obliged.
I value the blog.Really looking forward to read more. Cool.
Wow, great article.Much thanks again. Want more.
This is one awesome blog.Really looking forward to read more. Great.
A round of applause for your article post.Really looking forward to read more. Really Great.
Awesome blog article.Thanks Again. Will read on…
Thanks again for the blog. Great.
Great blog article.Really looking forward to read more. Much obliged.
Appreciate you sharing, great post.Much thanks again. Want more.
I really enjoy the blog post.Much thanks again. Will read on…
Great article.
Looking forward to reading more. Great post.Thanks Again. Much obliged.
Really informative post.Thanks Again. Keep writing.
A big thank you for your article. Much obliged.
I appreciate you sharing this blog.Much thanks again. Want more.
Great article.Really thank you! Keep writing.
I like what you guys are up too. This type of clever work and reporting!
Keep up the superb works guys I’ve you guys to my blogroll.
Wow, great blog.Really looking forward to read more. Much obliged.
I cannot thank you enough for the blog article.Much thanks again. Keep writing.
I cannot thank you enough for the blog article. Awesome.
Thanks a lot for the blog.
Im obliged for the article.Really thank you! Great.
Awesome post. Awesome.
Looking forward to reading more. Great article post.Thanks Again. Really Great.
I loved your blog.Thanks Again. Awesome.
Muchos Gracias for your article post.Really looking forward to read more. Cool.
Major thankies for the blog.Really thank you! Will read on…
Awesome blog.Much thanks again. Want more.
Major thanks for the blog article.Really thank you! Really Great.
wow, awesome blog article.Thanks Again.
Very neat article post.Thanks Again. Cool.
Very good blog post. Keep writing.
Thank you for your article post.Really looking forward to read more. Awesome.
Hi, I would like to subscribe for this website to take latest updates, therefore where can i do it please assist.
Im grateful for the blog article.Thanks Again. Cool.
Thanks for a marvelous posting! I certainly enjoyed reading it, you may be a great author.
I will be sure to bookmark your blog and may come back
sometime soon. I want to encourage yourself to continue
your great writing, have a nice afternoon!
Enjoyed every bit of your blog.Really thank you! Really Cool.
I am so grateful for your blog post. Really Great.
Thanks a lot for the article post.Really looking forward to read more. Will read on…
Very neat post.Really thank you! Fantastic.
Thanks-a-mundo for the article post.Really looking forward to read more. Want more.
Hey, thanks for the article post. Awesome.
Enjoyed every bit of your blog post.Really thank you! Great.
This is one awesome post.Really thank you! Keep writing.
Wow, great article.
Thanks for sharing, this is a fantastic post.Really thank you!
Thank you for your blog. Really Cool.
I truly appreciate this post.Really thank you! Keep writing.
What’s up, this weekend is pleasant in favor of me, as this point in time i am reading this
impressive educational article here at my house.
Very good post.Really looking forward to read more.
Major thanks for the blog post.Much thanks again. Fantastic.
Im thankful for the article.Really looking forward to read more. Keep writing.
I am so grateful for your blog. Will read on…
I appreciate you sharing this blog.Thanks Again.
I think this is a real great blog post.Much thanks again. Keep writing.
Really enjoyed this post.Really looking forward to read more. Want more.
I really liked your article post.Really looking forward to read more. Much obliged.
Really appreciate you sharing this article post.Really looking forward to read more. Great.
This post will assist the internet users for creating new web site or even a weblog from start to end.
I value the blog post.Really looking forward to read more. Will read on…
Awesome article.Really looking forward to read more. Awesome.
I really liked your blog post.
I loved your article.Thanks Again. Really Cool.
I love it when people come together and share ideas. Great blog, stick with it!
wow, awesome blog post. Awesome.
I value the blog post.Much thanks again. Awesome.
Im grateful for the article.Really thank you! Want more.
Great article. Fantastic.
Very neat blog. Will read on…
I think this is a real great blog article. Fantastic.
I value the blog.Much thanks again. Really Cool.
Wow, great post.Much thanks again. Fantastic.
Im grateful for the blog post.Much thanks again. Want more.
Thanks-a-mundo for the blog.Thanks Again. Fantastic.
Looking forward to reading more. Great blog.Much thanks again. Really Cool.
I really like and appreciate your blog article.Thanks Again. Really Cool.
Looking forward to reading more. Great blog article.Really looking forward to read more. Really Cool.
wow, awesome blog.Much thanks again. Cool.
Thanks again for the blog.Much thanks again. Really Great.
A round of applause for your blog.Thanks Again. Really Great.
Major thanks for the article.Really thank you! Will read on…
Wow, great blog article.Really thank you! Will read on…
hello!,I really like your writing so a lot! proportion we be in contact more about your article on AOL?
I need an expert in this space to resolve my problem. Maybe that’s you!
Looking forward to see you.
This is one awesome blog.Much thanks again. Cool.
I think this is a real great article post.Really looking forward to read more. Really Cool.
I am so grateful for your blog post.Much thanks again. Much obliged.
I appreciate you sharing this blog article.Thanks Again. Keep writing.
Im grateful for the article.Really thank you! Cool.
Thanks for sharing, this is a fantastic post.Thanks Again. Cool.
Great, thanks for sharing this article post.Really thank you! Great.
Nice post. I learn one thing more challenging on different blogs everyday. It can at all times be stimulating to learn content material from different writers and apply slightly something from their store. I’d prefer to make use of some with the content on my weblog whether you don’t mind. Natually I’ll offer you a hyperlink in your web blog. Thanks for sharing.
Enjoyed every bit of your blog.Thanks Again.
Say, you got a nice post.Much thanks again. Really Great.
Say, you got a nice blog post.Thanks Again. Really Cool.
Appreciate you sharing, great blog post.Really thank you! Fantastic.
Awesome blog post.Really looking forward to read more. Great.
Wow, great article post.Thanks Again. Really Cool.
Looking forward to reading more. Great blog.Thanks Again. Fantastic.
Say, you got a nice blog post.Thanks Again. Keep writing.
Thank you ever so for you post.Really thank you!
Thank you for your post.Thanks Again. Really Cool.
I think this is a real great article. Will read on…
Thanks again for the post. Much obliged.
Really appreciate you sharing this blog post.Really thank you! Great.
Thanks so much for the blog.Really looking forward to read more. Great.
I really like and appreciate your blog article.Much thanks again. Really Cool.
Very neat article post.Thanks Again. Great.
I am so grateful for your article. Really Great.
I really like and appreciate your blog. Really Cool.
Appreciate you sharing, great blog post.Thanks Again. Cool.
Thanks-a-mundo for the blog. Keep writing.
Awesome blog.Really thank you! Really Cool.
wow, awesome blog article.Really thank you! Really Cool.
Awesome blog.Thanks Again. Cool.
I really liked your blog article.Really looking forward to read more.
Awesome blog.Thanks Again. Awesome.
Thanks a lot for the blog post.Really thank you!
Hey, thanks for the blog article.Much thanks again. Will read on…
Thank you for your blog.Really thank you! Really Great.
Hey, thanks for the article. Great.
Hey, thanks for the blog.Thanks Again.
I truly appreciate this blog post. Great.
A round of applause for your blog post.Really thank you! Much obliged.
Thanks again for the post.Much thanks again. Cool.
Im obliged for the article.Thanks Again. Much obliged.
Wow, great article post.Much thanks again. Great.
Great, thanks for sharing this article.Really looking forward to read more. Great.
Thanks so much for the post.Much thanks again. Really Cool.
Really appreciate you sharing this post.Really thank you! Much obliged.
Enjoyed every bit of your blog.Thanks Again. Much obliged.
Thanks for the article post. Will read on…
Looking forward to reading more. Great post.Much thanks again. Much obliged.
Enjoyed every bit of your blog.Really looking forward to read more. Fantastic.
I am so grateful for your post.Thanks Again. Awesome.