# Tony Hyun Kim
# 2013 10 03
# CS 224w, PS 1, Problem 1

import snap

source = "email_network.txt"
G = snap.LoadEdgeList(snap.PNGraph, source, 0, 1)
snap.PrintInfo(G)

# Part b: Determine the basic bow-tie structure of the email graph
sccCntV = snap.TIntPrV()
snap.GetSccSzCnt(G, sccCntV)

print "SCC-size count"
for scc in sccCntV:
    print "{} {}".format(scc.GetVal1(), scc.GetVal2()) # (Num nodes in SCC, Num such components)

largest_scc = snap.GetMxScc(G)
sz_largest_scc = largest_scc.GetNodes()

random_nid_in_scc = largest_scc.GetRndNId()
print "Random NId in MxSCC: {}".format(random_nid_in_scc)

# Find the out- and in-components
outcomp = snap.GetBfsTree(G, random_nid_in_scc, True,  False)
incomp  = snap.GetBfsTree(G, random_nid_in_scc, False, True)

sz_outcomp = outcomp.GetNodes()
sz_incomp  = incomp.GetNodes()
print "Size of out-component: {}".format(sz_outcomp - sz_largest_scc)
print "Size of  in-component: {}".format(sz_incomp  - sz_largest_scc)
