00001
00002
00003
00004
00005
00006 import sys
00007
00008 class Int:
00009 def __init__(self,num):
00010 self.value = num
00011
00012 def inc(self,num):
00013 self.value+=num
00014
00015 def __repr__(self):
00016 return str(self.value)
00017
00018 def runme(infile,outfile,cutoff):
00019 fin = open(infile,'r')
00020 fout = open(outfile,'w')
00021 tree = {}
00022 count = 0
00023
00024 for line in fin.xreadlines():
00025
00026 a = line.split()
00027 id = int(a.pop(0))
00028 tot = int(a.pop(0))
00029 if tot < cutoff: break
00030 head = int(a.pop(0))
00031
00032 for node in a:
00033 val = int(node)
00034 key = (head,val)
00035
00036 n = tree.get(key)
00037 if n == None:
00038 tree[key] = Int(tot)
00039 else:
00040 n.inc(tot)
00041 head = val
00042
00043 count += 1
00044
00045 for node in tree.items():
00046
00047 print >>fout, node[1], ' ', node[0][0], ' ', node[0][1]
00048
00049 if __name__ == "__main__":
00050 if len(sys.argv) < 4:
00051 print "usage: ", sys.argv[0], " in_tree_file out_edge_file cutoff"
00052 sys.exit(1)
00053
00054 infile = sys.argv[1]
00055 outfile = sys.argv[2]
00056 cutoff = int(sys.argv[3])
00057 print "cutoff=",cutoff
00058
00059 runme(infile, outfile, cutoff)