文件名称:闭包搜索算法java编程
文件大小:4KB
文件格式:JAVA
更新时间:2012-04-14 05:34:35
查找并发事件
It is important in distributed computer systems to identify those events (at identifiable points in time) that are concurrent, or not related to each other in time. A group of concurrent events may sometimes attempt to simultaneously use the same resource, and this could cause problems. Events that are not concurrent can be ordered in time. For example, if event 1 can be shown to always precede event 2 in time, then event 1 and 2 are obviously not concurrent. Notationally we indicate that event 1 precedes 2 by writing 1 ! 2. Note that the precedes relation is transitive, as expected. Thus if 1 ! 2 and 2 ! 3, then we can also note that 1 ! 3. Sequential events in a single computation are not concurrent. For example, if a particular computation performs the operations identified by events 1, 2 and 3 in that order, then clearly and 1 ! 2 and 2 ! 3. Computations in a distributed system communicate by sending messages. If event 1 corresponds to the sending of a message by one computation, and event 2 corresponds to the reception of that message by a different computation, then we can always note that 1 ! 2, since a message cannot be received before it is sent. In this problem you will be supplied with lists of sequential events for an arbitrary number of computations, and the identification of an arbitrary number of messages sent between these computations. Let n be the number of events. Your task is to write an O(n3) program to find out how many pairs of events are concurrent. Input The input will include first an integer, nc, specifying the number of computations in the test case. For each of these nc computations there will be a single line containing an integer ne that specifies the number of sequential events in the computation followed by ne event IDs. Following the specification of the events in the last computation there will be a line with a single integer, nm, that specifies the number of messages that are sent between computations. Finally, on each of the following nm lines there will be a pair of event IDs specifying the name of the event associated with the sending of a message, and the event associated with the reception of the message. These IDs will have previously appeared in the lists of events associated with computations. e.g.: 2 2 1 2 2 3 4 1 3 1 Output Your output should be the number of pairs of concurrent events. e.g., the output for the above input should be: 2