F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Dressing

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5460    Accepted Submission(s): 2375


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
2 2 2 0 2 2 2 1 clothes 1 pants 1 2 2 2 2 clothes 1 pants 1 pants 1 shoes 1 0 0 0
 

Sample Output
8 6 5
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-26 04:07:56, Gzip enabled