Bzoj 1570: [Jsoi2008]blue Mary's Trip

Source: Internet
Author: User

Description After a period of time, the network company finally has a certain popularity, also began to receive some orders, of which the largest one from the city of B. Blue Mary decided to sign the order in person. To save money on travel, one of his financial advisers suggested buying only u airline tickets. U airlines have only one flight per day, and are all arriving in the afternoon on the day of departure, so they can only take one flight per day. After investigation, they were given detailed information on all flights operated by U Airways, which included the departure of each flight, the destination, and the number of votes to be picked up on one day. (Note: For a certain flight, whichever day they are able to buy the most, the number of votes on the day of departure will be the same.) Blue Mary notes that they will be able to reach City B from City a only on a U-airline flight, but they may not be able to reach B city on the same day due to the limited number of tickets that can be purchased on each flight. So now that Blue Mary needs your help, design a travel plan to make the arrival time of the last person arriving in City b the earliest. The first line of input contains 3 positive integers n,m and T. All cities that appear in the title are numbered,..., N, with City a number must be 1, City B must be n. U company has a total of M (one-way) flights. And even Blue Mary, the company has a total of t individual to go from a city to B city. The following m lines, each line containing 3 positive integers, x, y, Z, represent the origin of each flight of the company, the destination and the number of votes that Blue Mary can buy on one day of the flight. (that is, on either day, Blue Mary can only buy tickets for Z-U airlines from City X to City Y.) ) Enter a maximum of one-way flights from one city to another city. Output has only one row and contains a positive integer that represents the earliest arrival time of the person who finally reached City B. Let's say that the day they first took the plane was the first day. Sample Input3 3 5
1 2 1
2 3 5
3 1 4

Sample Output6
HINT

Conventions:
2 <= N <= 50
1 <= M <= 2450
1 <= T <= 50
1 <= x, y <= N
X! = Y
1 <= Z <= 50

Source

Have done an emergency evacuation of the problem is one eye, consider the two answers and then split by time with a full stream to check;

Note that the upper bound of the two points is n+tot, because the tot individual queue to go, a start set to N*tot crazy T;

Made by qt666#include<iostream> #include <cstdio> #include <algorithm> #include <cstring># Include<vector>using namespace Std;typedef long long ll;const int n=200050;const int Inf=19260817;int Head[N],to[N ],nxt[n],s[n],s,t,cnt=1,level[n],vis[n],q[n*10],f,n,m,tot;void addedge (int x,int y,int z) {TO[++CNT]=Y,S[CNT]=Z,NXT [Cnt]=head[x],head[x]=cnt;} void lnk (int x,int y,int z) {addedge (x, y, z); Addedge (y,x,0);}    BOOL BFs () {for (int i=s;i<=t;i++) level[i]=0,vis[i]=0;    int t=0,sum=1;    Q[0]=s,level[s]=1,vis[s]=1;    while (t<sum) {int now=q[t++];if (now==t) return 1;for (int i=head[now];i;i=nxt[i]) {int y=to[i];    if (Level[y]==0&&s[i]) {level[y]=level[now]+1;q[sum++]=y; }}} return 0;}    int dfs (int now,int maxf) {if (now==t) return MAXF;    int ret=0; for (int i=head[now];i;i=nxt[i]) {int y=to[i],f=s[i];if (level[y]==level[now]+1&&f) {int minn=min (MAXF-RET,F)    ;    F=dfs (Y,minn);    S[i]-=f;s[i^1]+=f;ret+=f; if (RET==MAXF) bReak;}    } if (!ret) level[now]=0; return ret;} void Dinic () {while (BFS ()) F+=dfs (S,inf);} struct data{int to,lim;}; vector<data> p[100];struct date{int id[2505];}    G[100];bool check (int mid) {memset (head,0,sizeof (head)); Cnt=1;int tt=0;    for (int i=1;i<=n;i++) {for (int j=0;j<=mid;j++) G[i].id[j]=++tt;    } s=0,t=tt+1;    for (int i=1;i<=n;i++) {for (int j=0;j<p[i].size (); j + +) {int x=p[i][j].to,lim=p[i][j].lim;    for (int k=0;k<mid;k++) {lnk (G[i].id[k],g[x].id[k+1],lim);    }}for (int k=0;k<mid;k++) lnk (G[i].id[k],g[i].id[k+1],inf);    } lnk (S,g[1].id[0],tot);    for (int i=0;i<=mid;i++) lnk (G[n].id[i],t,inf);    F=0;dinic (); return f==tot;    }int Main () {scanf ("%d%d%d", &n,&m,&tot);    for (int i=1;i<=m;i++) {int x,y,z;scanf ("%d%d%d", &x,&y,&z);p [X].push_back ((data) {y,z});    } int l=0,r=n+tot,ans=0;    while (l<=r) {int mid= (l+r) >>1;if (check (mid)) R=mid-1,ans=mid;else l=mid+1; } printf ("%d\n", ans);    return 0;} 

Bzoj 1570: [Jsoi2008]blue Mary's Trip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.