【BZOJ 1391】[Ceoi2008] order

题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1391

喜闻乐见大水题

#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int N = 10000;
const int M = 4000000;
const int INF = 1000000000;

int n,m,head[N],nxt[M],to[M],flow[M],dis[N],cur[N],S,T,vout;
queue<int> que;

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 void Add_Edge(int u, int v, int f) {
	static int TT = 1;
	to[++TT] = v; nxt[TT] = head[u]; head[u] = TT; flow[TT] = f;
	to[++TT] = u; nxt[TT] = head[v]; head[v] = TT; flow[TT] = 0;
}

inline bool BFS(){
    memset(dis,-1,sizeof(dis));
    dis[S] = 0; que.push(S);
    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 == T) 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]));
            ret += tmp; f -= tmp; flow[i] -= tmp; flow[i^1] += tmp;
            if (!f) break;
        } return ret;
    }
}
  
inline int Dinic(){
    int ret = 0; while (BFS()) {
        memcpy(cur,head,sizeof(head));
        ret += DFS(S,INF);
    } return ret;
}

int main(){
	n = read(); m = read(); S = 0; T = N-1;
	for (int i=1,t1,t2,t3;i<=n;i++) {
		t1 = read(); Add_Edge(S,i,t1); vout += t1;
		for (t2=read();t2;t2--) t3 = read(), Add_Edge(i,n+t3,read());
	}
	for (int i=1;i<=m;i++) Add_Edge(n+i,T,read());
	printf("%d\n",vout-Dinic());
	return 0;
}

81 thoughts to “【BZOJ 1391】[Ceoi2008] order”

  1. Aw, this was a very good post. Taking a few minutes and
    actual effort to produce a very good article… but what can I say… I hesitate a whole lot and don’t manage to get anything done.

  2. I’m really impressed with your writing skills and also with the layout on your blog.
    Is this a paid theme or did you customize it
    yourself? Anyway keep up the nice quality writing, it’s rare to see
    a great blog like this one nowadays.

  3. Great blog! Do you have any suggestions for aspiring writers?
    I’m hoping to start my own website soon but I’m a little lost on everything.

    Would you recommend starting with a free platform like WordPress
    or go for a paid option? There are so many options out there that I’m totally confused ..

    Any ideas? Appreciate it!

  4. I got this web page from my pal who informed me about this web site and now this time I am browsing this
    web site and reading very informative articles at this place.

  5. Thanks for any other excellent post. Where else may just anybody get
    that type of information in such a perfect approach of writing?
    I’ve a presentation next week, and I am at the search for
    such information.

  6. With havin so much content and articles do you ever run into
    any issues of plagorism or copyright violation?
    My site has a lot of unique content I’ve either authored myself or outsourced but it appears a
    lot of it is popping it up all over the internet without my authorization. Do you know any ways to help reduce content from being
    stolen? I’d definitely appreciate it.

  7. When I initially left a comment I seem to have clicked on the -Notify
    me when new comments are added- checkbox and from now on each time a comment is added I get four emails
    with the exact same comment. Perhaps there is an easy method you can remove me from that service?
    Thanks!

  8. I’m extremely inspired with your writing abilities and
    also with the layout for your weblog. Is this a paid theme or did you
    customize it yourself? Either way keep up the nice quality writing, it’s uncommon to
    look a nice blog like this one today..

  9. Yesterday, while I was at work, my cousin stole my iphone and tested to
    see if it can survive a 30 foot drop, just so she can be a youtube sensation. My iPad is now destroyed and she has 83 views.
    I know this is totally off topic but I had to share it with someone!

  10. It’s appropriate time to make some plans for the future and it’s time to be happy.
    I’ve read this post and if I could I wish to suggest
    you some interesting things or tips. Maybe you could write
    next articles referring to this article. I want to read even more things about
    it!

  11. I’m extremely impressed with your writing skills and also with the layout
    on your blog. Is this a paid theme or did you customize it yourself?

    Either way keep up the excellent quality writing, it
    is rare to see a nice blog like this one
    these days.

  12. Wow! This blog looks just like my old one! It’s on a totally different subject but it has pretty
    much the same layout and design. Outstanding choice of colors!
    natalielise plenty of fish

  13. It’s a shame you don’t have a donate button! I’d most certainly donate to this
    superb blog! I suppose for now i’ll settle for bookmarking and
    adding your RSS feed to my Google account. I look forward to fresh updates and
    will share this site with my Facebook group. Talk soon!

  14. This design is incredible! You definitely know how to keep a reader amused.
    Between your wit and your videos, I was almost moved
    to start my own blog (well, almost…HaHa!) Great job. I really enjoyed what you had to say,
    and more than that, how you presented it. Too cool!

  15. Oh my goodness! Amazing article dude! Thanks,
    However I am going through issues with your RSS. I don’t know the reason why
    I can’t subscribe to it. Is there anyone else getting the same RSS problems?

    Anyone that knows the solution can you kindly respond? Thanks!!

  16. Good day! Do you know if they make any plugins to help with
    Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains.
    If you know of any please share. Thank you!

  17. Howdy! This is my first visit to your blog! We are a
    collection of volunteers and starting a new initiative in a
    community in the same niche. Your blog provided us valuable information to work on. You have done
    a outstanding job!

  18. What’s Going down i am new to this, I stumbled upon this
    I’ve discovered It positively useful and it has helped me out loads.
    I hope to contribute & aid different users like its aided me.
    Good job.

  19. Hey! This is my 1st comment here so I just wanted to
    give a quick shout out and say I genuinely enjoy reading through
    your blog posts. Can you suggest any other blogs/websites/forums that go
    over the same topics? Thanks!

  20. Hey! I just wanted to ask if you ever have any issues with hackers?
    My last blog (wordpress) was hacked and I ended up losing several weeks of
    hard work due to no back up. Do you have any solutions
    to protect against hackers?

  21. I loved as much as you will receive carried out right here.
    The sketch is tasteful, your authored material stylish.
    nonetheless, you command get got an shakiness over that
    you wish be delivering the following. unwell unquestionably come
    more formerly again since exactly the same nearly very often inside
    case you shield this increase.

  22. I’m really impressed with your writing skills and also with the layout on your blog.
    Is this a paid theme or did you customize it yourself?
    Anyway keep up the excellent quality writing, it’s rare to see a
    great blog like this one today.

  23. Howdy! I could have sworn I’ve been to this
    site before but after checking through some of the post I realized it’s new to me.
    Anyhow, I’m definitely delighted I found it and
    I’ll be book-marking and checking back often!

  24. A person essentially assist to make critically articles I’d state.
    That is the first time I frequented your website page and up to now?
    I amazed with the analysis you made to make this particular put up incredible.
    Great process!

  25. certainly like your website however you have to test the spelling on quite a few of your posts.
    A number of them are rife with spelling problems and I find it very troublesome to inform the reality nevertheless I will surely come back again.

  26. Having read this I believed it was very informative.

    I appreciate you spending some time and effort to put this informative article together.
    I once again find myself personally spending a
    significant amount of time both reading and leaving comments.
    But so what, it was still worth it!

  27. I loved as much as you’ll receive carried out right here.
    The sketch is attractive, your authored material stylish.
    nonetheless, you command get got an shakiness over that you wish be delivering the following.
    unwell unquestionably come more formerly again as exactly the same nearly a
    lot often inside case you shield this increase.

  28. I am extremely impressed with your writing skills as well as with the layout
    on your blog. Is this a paid theme or did you customize it
    yourself? Either way keep up the nice quality writing, it’s rare
    to see a great blog like this one these days.

  29. Howdy! I could have sworn I’ve been to this web site before but after looking at some of
    the posts I realized it’s new to me. Nonetheless, I’m certainly happy I discovered it and I’ll be bookmarking it
    and checking back frequently!

  30. Hey there, I think your blog might be having browser compatibility issues.
    When I look at your blog site in Chrome, it looks fine but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that, superb
    blog!

  31. I was very happy to search out this web-site.I needed to thanks in your time for this wonderful learn!! I positively enjoying every little bit of it and I have you bookmarked to take a look at new stuff you blog post.

  32. I every time used to study article in news papers but now as I am a user of net therefore from now I
    am using net for posts, thanks to web.

  33. Howdy! This post could not be written any better!

    Reading this post reminds me of my previous room mate!
    He always kept chatting about this. I will forward this page to him.
    Pretty sure he will have a good read. Thank you for sharing!

  34. excellent points altogether, you just gained a new reader.
    What may you suggest about your put up that you just made some days in the past?
    Any sure?

  35. obviously like your web site but you need to check the spelling on quite a few of your
    posts. Many of them are rife with spelling issues and I find it
    very bothersome to tell the reality then again I will definitely come again again.

Leave a Reply

Your email address will not be published. Required fields are marked *