题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4519
分治+最小割
具体来说,假设随便选两个点来做一次最小割x
那么左右点被分成了两个点集,而任意一对存在于不同点集的点的最小割与x的割相等
于是只用考虑每个点集内部的点,接下来的事就是坚持信仰了
#include<bits/stdc++.h> #define LL long long #define abs(x) ((x)>0?(x):-(x)) using namespace std; const int N = 850+9; const int M = 8500*2+9; const int INF = 100000000; int head[N],nxt[M],to[M],flow[M],cur[N]; int n,m,vout[N*N],cnt,id[N],dis[N],pur,T=1; queue<int> que; inline void Add_Edge(int u, int v, int w) { to[++T] = v; nxt[T] = head[u]; head[u] = T; flow[T] = w; to[++T] = u; nxt[T] = head[v]; head[v] = T; flow[T] = w; } inline int read(){ char c=getchar(); int ret=0,f=1; while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();} while (c<='9'&&c>='0') ret=ret*10+c-'0',c=getchar(); return ret*f; } inline bool BFS(int s, int t) { memset(dis,-1,sizeof(dis)); que.push(s); dis[s] = 0; while (!que.empty()) { int w = que.front(); que.pop(); for (int i=head[w];i;i=nxt[i]) if (flow[i] && !~dis[to[i]]) dis[to[i]] = dis[w] + 1, que.push(to[i]); } return ~dis[t]; } int DFS(int w, int f) { if (w == pur) return f; else { int ret = 0; for (int &i=cur[w];i;i=nxt[i]) if (flow[i] && dis[to[i]] == dis[w] + 1) { int tmp = DFS(to[i], min(f, flow[i])); flow[i] -= tmp; flow[i^1] += tmp; ret += tmp; f -= tmp; if (!f) return ret; } return ret; } } inline int Dinic(int s, int t){ int ret = 0; pur = t; while (BFS(s,t)) { memcpy(cur,head,sizeof(head)); ret += DFS(s,INF); } return ret; } void SIGN(int w) { dis[w] = 1; for (int i=head[w];i;i=nxt[i]) if (!~dis[to[i]] && flow[i]) SIGN(to[i]); } void solve(int l , int r){ if (l >= r) return ; static int tmp[N]; int L=l-1, R=r+1; for (int i=2;i<=T;i+=2) flow[i] = flow[i^1] = flow[i] + flow[i^1] >> 1; vout[++cnt] = Dinic(id[l],id[r]); memset(dis,-1,sizeof(dis)); SIGN(id[l]); for (int i=l;i<=r;i++) if (~dis[id[i]]) tmp[++L] = id[i]; else tmp[--R] = id[i]; for (int i=l;i<=r;i++) id[i] = tmp[i]; solve(l,L); solve(R,r); } int main(){ n = read(); m = read(); for (int i=1,u,v,w;i<=m;i++) u = read(), v = read(), w = read(), Add_Edge(u,v,w); for (int i=1;i<=n;i++) id[i] = i; solve(1,n); int tot = 0; sort(vout+1,vout+1+cnt); for (int i=1;i<=cnt;i++) if (vout[i] != vout[i-1]) tot++; printf("%d\n",tot); return 0; }
314844 911770Sounds like some thing a lot of baby boomers need to study. The feelings of neglect are there in numerous levels when a single is over the hill. 854625
281255 931108Thank you for the very good writeup. It in fact was a amusement account it. Appear advanced to far added agreeable from you! Even so, how could we communicate? 519634
636798 764513I was trying to discover this. Truly refreshing take on the details. Thanks a great deal. 305771
After looking at a handful of the blog posts on your web page, I honestly
appreciate your technique of writing a blog. I bookmarked it to my bookmark site list and will be checking back in the near future.
Please visit my website as well and let me know what you think.
My brother suggested I might like this blog. He was entirely right.
This post truly made my day. You can not imagine just how much
time I had spent for this info! Thanks!
221804 430220Wow Da weiss man, wo es hingehen muss Viele Grsse Mirta 38949
hi!,I really like your writing very a lot! proportion we
keep up a correspondence extra approximately your post on AOL?
I require a specialist on this area to unravel my problem.
Maybe that is you! Taking a look forward to look you.
167855 193106I just added this weblog to my rss reader, exceptional stuff. I like your writing style. 272773
897531 153211Some genuinely excellent blog posts on this internet website , regards for contribution. 594603
461344 482650Perfectly written subject material , thanks for selective information . 381839
I was suggested this blog by way of my cousin.
I am no longer positive whether or not this publish is
written by way of him as no one else recognize such distinct approximately my
difficulty. You are incredible! Thanks!
107894 188122I like what you guys are up also. Such intelligent work and reporting! Keep up the superb works guys Ive incorporated you guys to my blogroll. I think itll improve the value of my web site . 345075
773073 73995Does your website have a contact page? Im having trouble locating it but, Id like to send you an e-mail. Ive got some suggestions for your blog you might be interested in hearing. Either way, excellent blog and I look forward to seeing it develop over time. 584905
Wow, marvelous blog layout! How long have you been blogging for?
you made blogging look easy. The overall look of your website is great, as well as the
content!
508319 698971Hey, you used to write amazing, but the last several posts have been kinda boring I miss your tremendous writings. Past few posts are just a little bit out of track! come on! 267794
Unquestionably believe that which you stated. Your favorite
reason seemed to be on the internet the simplest thing to be aware of.
I say to you, I certainly get irked while people think about
worries that they just do not know about. You managed to hit the
nail upon the top and also defined out the whole thing without having side-effects
, people could take a signal. Will likely be back to get
more. Thanks
Excellent goods from you, man. I have have in mind your stuff previous to and
you are simply extremely excellent. I actually like what you’ve acquired here, really like
what you are saying and the best way during which you are saying it.
You’re making it entertaining and you continue to care for to keep it sensible.
I cant wait to read much more from you. This is actually a tremendous web site.
It is appropriate time to make some plans for the future and it is time to be happy.
I’ve read this post and if I could I wish to
suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article.
I desire to read more things about it!
each time i used to read smaller content which also clear their motive, and that is also
happening with this article which I am reading at this place.
A person necessarily lend a hand to make seriously articles I’d state.
That is the very first time I frequented your website
page and up to now? I amazed with the research you made to make this
actual post amazing. Magnificent activity!
I’ve been surfing online greater than 3 hours these days, yet I
never discovered any attention-grabbing article like
yours. It is beautiful value enough for me. In my view, if all site owners
and bloggers made good content as you probably
did, the internet will probably be a lot more helpful than ever before.
Hello, Neat post. There is a problem with your site in internet explorer, could check this?
IE nonetheless is the marketplace leader and a huge element of people will leave out
your magnificent writing because of this problem.
Hey there! I just wanted to ask if you ever have any trouble with hackers?
My last blog (wordpress) was hacked and I ended up losing months of hard work due to
no backup. Do you have any methods to stop hackers?
I’ve been browsing online more than three hours as of late, yet I never discovered any
fascinating article like yours. It’s pretty value enough for me.
Personally, if all web owners and bloggers made excellent content material as you
probably did, the internet will be a lot more useful than ever before.
Why visitors still use to read news papers when in this technological globe all is accessible on web?
I simply could not go away your site before suggesting that I actually enjoyed the usual information a person supply for your visitors?
Is gonna be back incessantly in order to check up on new posts
Great article, just what I wanted to find.
Hi there just wanted to give you a quick heads up. The text in your content seem to be running off the screen in Internet
explorer. I’m not sure if this is a formatting issue or something to do with internet browser
compatibility but I thought I’d post to let you know. The style and design look great though!
Hope you get the issue fixed soon. Thanks
Yesterday, while I was at work, my cousin stole my iPad and tested to
see if it can survive a forty foot drop, just so she can be
a youtube sensation. My iPad is now broken and she has 83
views. I know this is totally off topic but I had to share it with someone!
Appreciating the hard work you put into your site and detailed information you provide.
It’s great to come across a blog every once in a while
that isn’t the same outdated rehashed information.
Great read! I’ve saved your site and I’m including your
RSS feeds to my Google account.
Great weblog here! Also your web site quite a bit up very fast!
What host are you the use of? Can I get your associate link on your host?
I desire my site loaded up as quickly as yours lol
I blog often and I genuinely appreciate your information. This article has really peaked my interest.
I am going to bookmark your website and keep checking for new details about once
a week. I subscribed to your RSS feed too.