sicily 1308. Dependencies among J

原创 2015年11月20日 20:58:18

1308. Dependencies among J


Time Limit: 1 secs, Memory Limit: 32 MB


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 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.


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




#include <iostream>
#include <vector>

struct Node {
  int cost;
  int papa[11];
  int count;
} nodes[10001];
int num, target;
int ans;

void deal(std::string line, int index) {
  int temp = 0;
  int i;
  for (i = 0; line[i] != ' ' && i < line.length(); ++i)
    temp = temp * 10 + (line[i]-'0');
  nodes[index].cost = temp;
  temp = 0;
  for (i = i + 1; i < line.length(); ++i) {
    if (line[i] == ' ') {
      nodes[index].papa[nodes[index].count++] = temp;
      temp = 0;
    } else {
      temp = temp * 10 + (line[i]-'0');
  if (temp != 0)
    nodes[index].papa[nodes[index].count++] = temp;

void dfs(int index) {
  ans += nodes[index].cost;
  nodes[index].cost = 0;
  for (int i = 0; i < nodes[index].count; ++i) {
    if (nodes[nodes[index].papa[i]].cost != 0)

int main()
  while (std::cin >> num && num != 0) {
    std::cin >> target;
    std::string line;
    getline(std::cin, line);
    for (int i = 0; i <= num; ++i)
      nodes[i].count = 0;
    for (int i = 1; i <= num; ++i) {
      getline(std::cin, line);
      deal(line, i);
    ans = 0;
    std::cout << ans << std::endl;



Sicily 1308. Dependencies among J

1308. Dependencies among J Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description As ...

Sicily 1308 Dependencies among J (SOJ 1308) 【BFS 广度优先搜索】

原题地址:点击打开链接 一开始以为是拓扑排序,因为看上去比较像,等写了一半后发现实际这题的做法和广搜是一样的。 ——————正文—————— 根据输入可以建立一个有向图,从目标点m开始,向前寻找...
  • fanfanK
  • fanfanK
  • 2013年05月20日 22:15
  • 1352

Scicily 1308 Dependencies among Job(2003年广东省赛题)

题目链接: 题目描述: 给出N项工作,以及工作之间的依赖关系,求出第M项工作的最早完成时间。其中第i项工作依赖于第j项工作表示,完成第j项工作之后才能完成第i项...


  • 2017年02月05日 14:54
  • 32.03MB
  • 下载


  • 2016年04月20日 14:57
  • 6.75MB
  • 下载

【DataStructure】The difference among methods addAll(),retainAll() and removeAll()

In the Java collection workframe, there are three similar methods, addAll(),retainAll() and removeAl...

『iOS/Obj-C』The difference among int, NSInteger, NSUInteger and NSNumber

The difference among _int, NSInteger, NSUInteger and NSNumber Apple iOS official document is a pret...

chanel outlet online Spring comes quietly and softly Have you made changes among your clothing apt a

Spring comes noiselessly plus lightly Have you made changes among your clothing to catch up with its...

Burberry Outlet online Variation among the products namely the main focus of the Hermes fashion hous

Variation surrounded the products namely the main focus of the Hermes fashion house which includes h...
您举报文章:sicily 1308. Dependencies among J