POJ3683 Priest John's Busiest Day(2-SAT)


Time Limit:?2000MS?Memory Limit:?65536KTotal Submissions:?11049?Accepted:?3767?Special Judge


亚博体育官网贵宾登录John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old legend in the town that the couple who get married on that day will be forever blessed by the God of Love. This year?N?couples plan to get married on the blessed day. The?i-th couple plan to hold their wedding from time?Si?to time?Ti. According to the traditions in the town, there must be a special ceremony on which the couple stand before the priest and accept blessings. The?i-th couple need?Di?minutes to finish this ceremony. Moreover, this ceremony must be either at the beginning or the ending of the wedding (i.e. it must be either from?Si?to?Si?+?Di, or from?Ti?-?Di?to?Ti). Could you tell John how to arrange his schedule so that he can present at every special ceremonies of the weddings.

Note that John can not be present at two weddings simultaneously.


The first line contains a integer?N?( 1 ≤?N?≤ 1000).?The next?N?lines contain the?Si,?Ti?and?Di.?Si?and?Ti?are in the format of?hh:mm.


The first line of output contains "YES" or "NO" indicating whether John can be present at every special ceremony. If it is "YES", output another?N?lines describing the staring time and finishing time of all the ceremonies.

Sample Input

208:00 09:00 3008:15 09:00 20

Sample Output

YES08:00 08:3008:40 09:00



POJ Founder Monthly Contest – 2008.08.31, Dagger and Facer?题意:有一个小镇上只有一个牧师。这个小镇上有一个传说,在九月一日结婚的人会受到爱神的保佑,但是要牧师举办一个仪式。这个仪式要么在婚礼刚刚开始的时候举行,要么举行完婚礼正好结束。?现在已知有n场婚礼,告诉你每一场的开始和结束时间,以及举行仪式所需要的时间。问牧师能否参加所有的婚礼,如果能则输出一种方案。?对于每一场婚礼,我们可以把它抽象成一个点对对于冲突的点,我们可以看做是利用选A不能选B的关系来进行限制这样这道题就变成了一道2-SAT问题然后按照套路用tarjan缩点,暴力建反向图,拓扑排序?
#include#include#include#include#include#include#define Pair pair#define F first#define S secondusing namespace std;const int MAXN=1e6+10;//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)char buf[1<<20],*p1=buf,*p2=buf;inline int read(){ char c=getchar();int x=0,f=1; while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f;}Pair P[MAXN];bool check(int x,int y){ if((P[x].S<=P[y].F)||(P[x].F>=P[y].S)) return 0; else return 1;}struct node{ int u,v,nxt;}edge[MAXN];int head[MAXN],num=1;inline void AddEdge(int x,int y){ edge[num].u=x; edge[num].v=y; edge[num].nxt=head[x]; head[x]=num++;}int dfn[MAXN],low[MAXN],vis[MAXN],color[MAXN],colornum=0,tot;stacks;void tarjan(int now){ dfn[now]=low[now]=++tot; vis[now]=1; s.push(now); for(int i=head[now];i!=-1;i=edge[i].nxt) { if(!dfn[edge[i].v]) tarjan(edge[i].v),low[now]=min(low[now],low[edge[i].v]); else if(vis[edge[i].v]) low[now]=min(low[now],dfn[edge[i].v]); } if(dfn[now]==low[now]) { int h;colornum++; do { h=s.top();s.pop(); color[h]=colornum; vis[h]=0; }while(h!=now); }}vectorE[MAXN];int enemy[MAXN],inder[MAXN],ans[MAXN];void Topsort(){ queueq; for(int i=1;i<=colornum;i++) if(inder[i]==0) q.push(i); while(q.size()!=0) { int p=q.front();q.pop(); if(!ans[p]) ans[p]=1,ans[enemy[p]]=-1; for(int i=0;i