Sicily 1308. Dependencies among J
来源:互联网 发布:网络老虎机熊猫机器 编辑:程序博客网 时间:2024/05/21 07:08
1308. Dependencies among J
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
As everybody knows, our staffs need to do a lot of jobs to prepare for GDCPC’2003 (ZSUCPC’2003). But I bet you can not image how terrible to arrange the jobs. We know, sometimes there are dependencies among the jobs. We say job 2 depends on job 1 that means before starting job 1 we must finish job 2. We assume that there is only one job processing in one moment, and any job is dependent on no more than ten jobs.
When we make up a jobs’ schedule, we should check whether it is valid. Now, your task is to find out the earliest finish time of some jobs.
Input
Input will contain several test cases. The first line of each test case contains two integer numbers N (0≤N≤10,000) and M. The jobs are numbered from 1 to N. You need to calculate the earliest finish time of the job M. And then, the following N lines describe jobs. The first line is corresponding the job 1, second line is corresponding the job 2 and so on.
Each job’s describing line contains several positive integer numbers. The numbers are separated by spaces. The first one of the ith line shows the time (≤100) that ith job cost. The rest of numbers of the ith line are the jobs on which the job I depends.
N=0 indicate the end of input file. We guaranteed there is no circle on dependency.
Output
For each test case you should output one line, and just one number in this line. The number is the earliest finishing time of job M.
Sample Input
2 232 13 332 14 1 20
Sample Output
59
Problem Source
ZSUACM Team Member
// Problem#: 1308// Submission#: 3279120// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <stdio.h>#include <iostream>#include <vector>#include <string>#include <stack>#include <iomanip>#include <algorithm>#include <queue>#include <functional>using namespace std;const int MAX_V = 10005;const int INF = 99999999;int N, M;vector<int> G[MAX_V];int cost[MAX_V];char in[MAX_V * 1000];void read() { for (int i = 1; i <= N; i++) { G[i].clear(); } for (int i = 1; i <= N; i++) { gets(in); int j = 0; int c = 0; int t = 0; for (; in[j] != ' ' && in[j] != '\0'; j++) { c = c * 10 + in[j] - '0'; } cost[i] = c; if (in[j] == '\0') continue; for (j++; 1; j++) { if (in[j] == ' ') { G[i].push_back(t); t = 0; } else if (in[j] == '\0') { G[i].push_back(t); break; } else { t = t * 10 + in[j] - '0'; } } }}bool haveTo[MAX_V];bool vis[MAX_V];void searchHaveTo(int from) { vis[from] = haveTo[from] = true; int s = G[from].size(); for (int i = 0; i < s; i++) { if (!vis[G[from][i]]) { true; searchHaveTo(G[from][i]); } }}int findAns() { for (int i = 1; i <= N; i++) haveTo[i] = vis[i] = false; haveTo[M] = vis[M] = true; int s = G[M].size(); for (int i = 0; i < s; i++) { if (!vis[G[M][i]]) { searchHaveTo(G[M][i]); } } int sum = 0; for (int i = 1; i <= N; i++) { if (haveTo[i]) sum += cost[i]; } return sum;}int main() { //std::ios::sync_with_stdio(false); while (1) { scanf("%d", &N); if (N == 0) break; scanf("%d\n", &M); read(); printf("%d\n", findAns()); } return 0;}
- Sicily 1308. Dependencies among J
- sicily 1308. Dependencies among J
- Sicily 1308 Dependencies among J (SOJ 1308) 【BFS 广度优先搜索】
- Sicily 1308 Dependencies among Jobs(图的搜索)
- Scicily 1308 Dependencies among Job(2003年广东省赛题)
- Dependencies
- J
- j
- j
- J#
- J
- J
- J
- J
- j
- J
- J
- J
- Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果
- Java多线程
- Sicily 1149. 等价表达式
- 认识编程语言(c++)
- Sicily 1923. Is It Nim?
- Sicily 1308. Dependencies among J
- FLV格式解析
- 如何找回tomcat管理员密码
- Sicily 1047. Super Snooker
- (2.1.1)JVM内容:Java 类加载与初始化
- Sicily 1454. Pseudoprime numbers
- Unity IK(反向运动学)初探
- 准备蓝桥杯--dyx--十进制转换十六进制
- Sicily 2506. 绝对值序列