Priest John's Busiest Day
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 10151   Accepted: 3475   Special Judge

Description

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.

Input

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.

Output

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

2
08:00 09:00 30
08:15 09:00 20

Sample Output

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int N=;
struct node{
int st,ed;
}e[N];
int dfn[N],low[N],bl[N],in[N],q[N],col[N],con[N];
bool instack[N];
int cnt,scnt,l,n;
vector<int>v[N];
vector<int>g[N];
void init(){
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(in));
memset(col,,sizeof(col));
memset(instack,,sizeof(instack));
for(int i=;i<=*n;++i) v[i].clear(),g[i].clear();
cnt=scnt=l=;
}
inline void add(int a,int b){v[a].push_back(b);}
void Tarjan(int u){
low[u]=dfn[u]=++cnt;
q[l++]=u;
instack[u]=;
for(int i=;i<(int)v[u].size();++i){
int x=v[u][i];
if(!dfn[x]){
Tarjan(x);
low[u]=min(low[u],low[x]);
}
else if(instack[x]&&dfn[x]<low[u]) low[u]=dfn[x];
}
if(low[u]==dfn[u]){
int t;++scnt;
do{
t=q[--l];
instack[t]=;
bl[t]=scnt;
}while(t!=u);
}
}
void rebuild(){
for(int i=;i<*n;++i) for(int j=;j<(int)v[i].size();++j){
int a=bl[i],b=bl[v[i][j]];
if(a==b) continue;
++in[a];
g[b].push_back(a);
}
}
void topsort(){
queue<int>Q;
for(int i=;i<=scnt;++i) if(!in[i]) Q.push(i);
while(!Q.empty()){
int u=Q.front();
Q.pop();
if(!col[u]) {
col[u]=;
col[con[u]]=;
}
for(int i=;i<(int)g[u].size();++i){
int x=g[u][i];
--in[x];
if(in[x]==) Q.push(x);
}
}
}
void solve(){
for(int i=;i<*n;++i) if(!dfn[i]) Tarjan(i);
for(int i=;i<n;++i) {
if(bl[*i]==bl[*i+]) {puts("NO");return;}
int a=bl[*i],b=bl[*i+];
con[a]=b;con[b]=a;
}
rebuild();
topsort();
puts("YES");
for(int i=;i<*n;i+=){
if(col[bl[i]]==) {
int h1=e[i].st/,m1=e[i].st%,h2=e[i].ed/,m2=e[i].ed%;
printf("%02d:%02d %02d:%02d\n",h1,m1,h2,m2);
}
else {
int h1=e[i^].st/,m1=e[i^].st%,h2=e[i^].ed/,m2=e[i^].ed%;
printf("%02d:%02d %02d:%02d\n",h1,m1,h2,m2);
}
}
}
int getx(char *s){
int h,m;
h=(s[]-'')*+s[]-'';
m=(s[]-'')*+s[]-'';
return h*+m;
}
bool Ju(const node &a,const node &b){
if (b.st>=a.st && b.st < a.ed) return ;
if(a.st>=b.st && a.st < b.ed) return ;
return ;
}
int main(){
char st[],ed[];
int time;
while(scanf("%d",&n)!=EOF){
init();
for(int i=;i<n;++i){
scanf("%s %s %d",st,ed,&time);
e[*i].st=getx(st);e[*i].ed=getx(st)+time;
e[*i+].st=getx(ed)-time;e[*i+].ed=getx(ed);
}
for(int i=;i<*n;++i)
for(int j=i+;j<*n;++j){
if(i==(j^)) continue;
if(Ju(e[i],e[j])) {add(i,j^);add(j,i^);}
}
solve();
}
}
YES
08:00 08:30
08:40 09:00

poj3683 2-SAT 同上一道的更多相关文章

  1. poj3683 2 -sat输出路径

    tarjan缩点,拓扑排序染色输出(貌似挑战上面没有拓扑啊,而且这样写还过了= =) 主要是找s,t,d,三者之间的关系,找出合取范式这题就很容易了 #include<map> #incl ...

  2. S - 骨牌铺方格(第二季水)

    Description          在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.         例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...

  3. zzuli 1875多线DP

    1875: 蛤玮的财宝 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 530  Solved: 116 SubmitStatusWeb Board De ...

  4. ZJOI2019Round#1

    考的这么差二试基本不用去了 不想说什么了.就把这几天听课乱记的东西丢上来吧 这里是二试乱听课笔记ZJOI2019Round#2 ZJOI Round#1 Day1 M.<具体数学>选讲 罗 ...

  5. POJ 3678 Katu Puzzle(2 - SAT) - from lanshui_Yang

    Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...

  6. 【一天一道LeetCode】#349. Intersection of Two Arrays

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...

  7. 【一天一道LeetCode】#165. Compare Version Numbers

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源: htt ...

  8. 【一天一道LeetCode】#84. Largest Rectangle in Histogram

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given n ...

  9. 【一天一道LeetCode】#54. Spiral Matrix

    一天一道LeetCode系列 (一)题目 Given a matrix of m x n elements (m rows, n columns), return all elements of th ...

随机推荐

  1. Spring Boot @EnableAutoConfiguration和 @Configuration的区别

    Spring Boot @EnableAutoConfiguration和 @Configuration的区别 在Spring Boot中,我们会使用@SpringBootApplication来开启 ...

  2. 《名侦探柯南》动画登陆bilibili

    不管你看没看过.喜不喜欢,也一定听说过<名侦探柯南>这部动画,它和<火影>.<海贼王>几部动画陪伴了一代人成长的道路,而且<名侦探柯南>还是这几部动画中 ...

  3. 在linux上搭建nacos集群(步骤详细,linux小白也搞得定)

    (1)nacos官网:https://github.com/alibaba/nacos/releases/tag/1.2.1下载nacos安装包到window本地(后缀为tar.zip) (2)在li ...

  4. sqlserver2005定期备份和清除

    1.打开管理->维护计划 2.右键点击新建维护计划 3.给新的维护计划自定义命名 4.可以看左下角的维护方式 5.拖动“备份数据库”到右边 6.选中,编辑备份方式 7.选择备份方式,所有数据库, ...

  5. Codeforces Round #626 D. Present

    D. Present 题目大意:给你一个大小是n的序列,求两两之间相加进行异或之后的答案. 这个题目我并没有想到怎么写,有点偷懒于是就去看了题解.. 题解很套路... 题解: 因为这个是用到了异或,所 ...

  6. G. 神圣的 F2 连接着我们 线段树优化建图+最短路

    这个题目和之前写的一个线段树优化建图是一样的. B - Legacy CodeForces - 787D 线段树优化建图+dij最短路 基本套路 之前这个题目可以相当于一个模板,直接套用就可以了. 不 ...

  7. 硬肝4.4w字为你写成Java开发手册

    先来看一下本篇文章的思维导图吧,我会围绕下面这些内容进行讲解.内容很干,小伙伴们看完还希望不吝转发.(高清思维导图版本关注作者公众号 Java建设者 回复 Java666 获取,其他思维导图获取方式在 ...

  8. Spring Cloud 学习 之 Spring Cloud Eureka(架构)

    Spring Boot版本:2.1.4.RELEASE Spring Cloud版本:Greenwich.SR1 文章目录 Eureka服务治理基础架构的三个核心要素: 服务治理机制: 服务提供者: ...

  9. 一阶RC高通滤波器详解(仿真+matlab+C语言实现)

    文章目录 预备知识 关于电容 HPF的推导 simulink 仿真 simulink 运行结果 matlab 实现 matlab 运行结果 C语言实现 如果本文帮到了你,帮忙点个赞: 如果本文帮到了你 ...

  10. CF-612D The Union of k-Segments 差分

    D. The Union of k-Segments 题意 给出n个线段,以及一个数字k,让求出有哪些线段:线段上所有的点至少被覆盖了k次. 思路 假如忽略掉线段的左右端点范围,肯定是使用差分来维护每 ...