|
||||||||||
DressingTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5546 Accepted Submission(s): 2405 Problem Description Wangpeng has N clothes, M pants and K shoes so theoretically he can have N¡ÁM¡ÁK different combinations of dressing. One day he wears his pants Nike, shoes Adiwang to go to school happily. When he opens the door, his mom asks him to come back and switch the dressing. Mom thinks that pants-shoes pair is disharmonious because Adiwang is much better than Nike. After being asked to switch again and again Wangpeng figure out all the pairs mom thinks disharmonious. They can be only clothes-pants pairs or pants-shoes pairs. Please calculate the number of different combinations of dressing under mom¡¯s restriction. Input There are multiple test cases. For each case, the first line contains 3 integers N,M,K(1¡ÜN,M,K¡Ü1000) indicating the number of clothes, pants and shoes. Second line contains only one integer P(0¡ÜP¡Ü2000000) indicating the number of pairs which mom thinks disharmonious. Next P lines each line will be one of the two forms¡°clothes x pants y¡± or ¡°pants y shoes z¡±. The first form indicates pair of x-th clothes and y-th pants is disharmonious(1¡Üx¡ÜN,1 ¡Üy¡ÜM), and second form indicates pair of y-th pants and z-th shoes is disharmonious(1¡Üy¡ÜM,1¡Üz¡ÜK). Input ends with ¡°0 0 0¡±. It is guaranteed that all the pairs are different. Output For each case, output the answer in one line. Sample Input
Sample Output
Source | ||||||||||
|