Merry Christmas

Time Limit : 8 sec, Memory Limit : 65536 KB

Problem J: Merry Christmas

International Christmas Present Company (ICPC) is a company to employ Santa and deliver presents on Christmas. Many parents request ICPC to deliver presents to their children at specified time of December 24. Although same Santa can deliver two or more presents, because it takes time to move between houses, two or more Santa might be needed to finish all the requests on time.

Employing Santa needs much money, so the president of ICPC employed you, a great program- mer, to optimize delivery schedule. Your task is to write a program to calculate the minimum number of Santa necessary to finish the given requests on time. Because each Santa has been well trained and can conceal himself in the town, you can put the initial position of each Santa anywhere.

Input

The input consists of several datasets. Each dataset is formatted as follows.

N M L
uvd1
uvd2
.
.
.
uM vM dM
pt1
pt2
.
.
.
pL tL

The first line of a dataset contains three integer, N , M and L (1 ≤ N ≤ 100, 0 ≤ M ≤ 1000, 1 ≤ L ≤ 1000) each indicates the number of houses, roads and requests respectively.

The following M lines describe the road network. The i-th line contains three integers, ui , vi , and di (0 ≤ ui < vi≤ N - 1, 1 ≤ di ≤ 100) which means that there is a road connecting houses ui and vi with di length. Each road is bidirectional. There is at most one road between same pair of houses. Whole network might be disconnected.

The next L lines describe the requests. The i-th line contains two integers, pi and ti (0 ≤ pi ≤ N - 1, 0 ≤ ti ≤ 108 ) which means that there is a delivery request to house pi on time ti . There is at most one request for same place and time. You can assume that time taken other than movement can be neglectable, and every Santa has the same speed, one unit distance per unit time.

The end of the input is indicated by a line containing three zeros separated by a space, and you should not process this as a test case.

Output

Print the minimum number of Santa necessary to finish all the requests on time.

Sample Input

3 2 3
0 1 10
1 2 10
0 0
1 10
2 0
3 2 4
0 1 10
1 2 10
0 0
1 10
2 20
0 40
10 10 10
0 1 39
2 3 48
3 5 20
4 8 43
3 9 10
8 9 40
3 4 5
5 7 20
1 7 93
1 3 20
0 0
1 100000000
2 100
3 543
4 500
5 400
6 300
7 200
8 100
9 100
0 0 0

Output for the Sample Input

2
1
4

题意:有L个货物需要圣诞老人派送,每个货物要送到谁家,并且几点之前送掉都有严格规定。准时送完全部的L个货物至少需要多少个圣诞老人。

思路:一开始我们考虑最坏的情况,即L个货物需要L个圣诞老人才能全部送完,之后再进行优化,找找是否可以少用圣诞来人。如果一个圣诞老人送完一个货物后有足够时间走到另外一个货物的送货地点,那么这两个货物可以由这一个圣诞老人一起送,这样就能少用一个圣诞老人。把所有能够一起送的两个货物之间都连上边,图的最大匹配即为能减少的圣诞老人个数x,L-x就是最少所需圣诞老人数。例如如下情况二分图:
                                     即为货物1送完可直接送货物2;货物2送完可直接送货物3;货物4送完可直接送货物5,货物5送完可直接送货物3,其最大匹配为3,那么一共可以节省3个圣诞老人。

代码:

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
const int N_MAX = + , V_MAX = + ;
int V;//点的个数
vector<int>G[N_MAX];
int match[N_MAX];
bool used[N_MAX];
void add_edge(int u, int v) {
G[u].push_back(v);
G[v].push_back(u);
} bool dfs(int v) {
used[v] = true;
for (int i = ; i < G[v].size(); i++) {
int u = G[v][i], w = match[u];
if (w < || !used[w] && dfs(w)) {
match[v] = u;
match[u] = v;
return true;
}
}
return false;
} int bipartite_matching() {
int res = ;
memset(match, -, sizeof(match));
for (int v = ; v < V; v++) {
if (match[v] < ) {
memset(used, , sizeof(used));
if (dfs(v))
res++;
}
}
return res;
}
int N, M, L, dis[N_MAX][N_MAX];
int p[N_MAX], t[N_MAX];
int main() { while (scanf("%d%d%d", &N, &M, &L) && N) {
V = * L;
memset(dis, INF, sizeof(dis));
for (int i = ; i < M; i++) {
int u, v, d;
scanf("%d%d%d", &u, &v, &d);
dis[u][v] = d;
dis[v][u] = d;
}
for (int i = ; i < L; i++) {
scanf("%d%d", p + i, t + i);
}
//floyd
for (int k = ; k < N; k++) {
dis[k][k] = ;//!!!!!!!!
for (int i = ; i < N; i++)
for (int j = ; j < N; j++) {
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
}
/////
for (int i = ; i < L; i++) {
for (int j = ; j < L; j++) {
if (i != j&&t[i] + dis[p[i]][p[j]] <= t[j]) {//可以从p[i]走到p[j]送货,少用一个人
add_edge( i, L+j);//连一条边,连边的两端货物可以让一个人送即可
}
}
}
printf("%d\n", L - bipartite_matching());
for (int i = ; i < V; i++)
G[i].clear();
} return ;
}

aoj 2226 Merry Christmas的更多相关文章

  1. AOJ 2251 Merry Christmas (最小点覆盖)

    [题目链接] http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2251 [题目大意] 给出一张图,现在有一些任务,要求在ti时刻送礼物 ...

  2. shit antd & Merry Christmas bug

    shit antd & Merry Christmas bug https://github.com/ant-design/ant-design/issues/13098 antd 玩大了? ...

  3. 《一头扎进》系列之Python+Selenium框架实战篇7 - 年底升职加薪,年终奖全靠它!Merry Christmas

    1. 简介 截止到上一篇文章为止,框架基本完全搭建完成.那么今天我们要做什么呢????聪明如你的小伙伴或者是童鞋一定已经猜到了,都测试完了,当然是要生成一份高端大气上档次的测试报告了.没错的,今天宏哥 ...

  4. 我的平安夜-Merry Christmas

    我的平安夜-Merry Christmas 平安夜给自己买的第一个"苹果",嘻嘻. 今夜,不想去学习技术知识点什么的, 我们就想到哪里写哪里,就简单聊聊思维方式吧. 其实我不想做今 ...

  5. Merry Christmas & Happy New Year!!

    圣诞快乐,新年快乐!

  6. merry Christmas

    圣诞节的来历 圣诞节这个名称是基督弥撒的缩写. 弥撒是教会的一种礼拜仪式. 1.耶诞节是一个宗节,我们把它当作耶苏的诞辰来庆祝,因而又名耶诞节.这一天,世界所有的基督教会都举行特别的礼拜仪式.但是有很 ...

  7. Merry Christmas 2015

    祝大家圣诞快乐! 昨天下班在电梯里遇见HR大BOSS,她说公司今天上午有2200个员工要带小孩子来参加Children's Holidy Party...我问了句,那是不是有免费早餐和午餐啊,她说 & ...

  8. pandaboy Merry Christmas

  9. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

随机推荐

  1. 《剑指offer》56 数组中只出现一次的数字

    题目描述 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字.   在线练习:https://www.nowcoder.com/practice/e02fdb5 ...

  2. python-判断alter是否存在

    from selenium import webdriver import time from selenium.webdriver.support.ui import WebDriverWait f ...

  3. iOS8之后,UITableViewRowAction实现滑动多个按钮

    #pragma mark - View lifeCycle - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = ...

  4. 【转】VC自定义消息

    MFC一般可利用ClassWizard类向导添加消息和消息处理函数,但用户自定义消息必须手工输入,现将vc自定义消息方法步骤记录如下: (1)定义消息 利用#define语句直接定义用户自己的消息(既 ...

  5. 【NOIP2017提高组模拟7.3】B

    树上路径统计,点分治解决. 统计一段区间,naive地用了set解决,这样的复杂度是O(nlog^2n)的 考场代码出了个问题,统计答案时找到了之前的最优答案,但是没有加上新的一段,导致60分 #in ...

  6. linux关于任务计划

    1.一次性任务计划:at 1)添加 在18:16时候重启服务器 at 18:16 >at init 6 >at ctrl+d2)查看 atq 1 Mon Aug 20 21:09:00 2 ...

  7. 《linux设备驱动开发详解》笔记——8阻塞与非阻塞IO

    8.1 阻塞与非阻塞IO 8.1.0 概述 阻塞:访问设备时,若不能获取资源,则进程挂起,进入睡眠状态:也就是进入等待队列 非阻塞:不能获取资源时,不睡眠,要么退出.要么一直查询:直接退出且无资源时, ...

  8. JDK1.8 HashMap$TreeNode.rotateLeft 红黑树左旋

    红黑树介绍 1.节点是红色或黑色. 2.根节点是黑色. 3.每个叶子节点都是黑色的空节点(NIL节点). 4 每个红色节点的两个子节点都是黑色.(从每个叶子到根的所有路径上不能有两个连续的红色节点) ...

  9. CDH4 journalnode方式手工安装手册之三

    一.                                启动JournalNode 每台机器都要执行: mkdir -p /smp/hadoop-cdh4/bch/ chmod -R 77 ...

  10. Clickonce - Change deployment URL after publish

    mage.exe -Update C:\inetpub\wwwroot\aspnet40\AminoScience\Uploads\Application Files\AccUFeed_1_0_0_5 ...