#include "Snap.h"

int main(int argc, char* argv[]) {
	// download the network from snap.stanford.edu/data/wiki-Vote.html
	PNGraph G = TSnap::LoadEdgeList<PNGraph>("wiki-Vote.txt.gz");
	// nodes
  printf("Number of nodes: %d\n", G->GetNodes());
  // edges
  THash<TIntPr, TInt> EdgeH;
  int SelfCnt=0;
	for (TNGraph::TEdgeI EI = G->BegEI(); EI < G->EndEI(); EI++) {
		EdgeH.AddKey(TIntPr(EI.GetSrcNId(), EI.GetDstNId()));
		if (EI.GetSrcNId() == EI.GetDstNId()) { SelfCnt++; }
	}
	printf("Nodes with a self-edge: %d\n", SelfCnt);
  printf("Directed edges: %d\n", EdgeH.Len());
  // undirected edges
  for (TNGraph::TEdgeI EI = G->BegEI(); EI < G->EndEI(); EI++) {
		EdgeH.AddKey(TIntPr(EI.GetSrcNId(), EI.GetDstNId()));
		EdgeH.AddKey(TIntPr(EI.GetDstNId(), EI.GetSrcNId()));
	}
	printf("UnDirected edges: %d\n", EdgeH.Len()/2);
	// bidirectional edges
	EdgeH.Clr();
	for (TNGraph::TEdgeI EI = G->BegEI(); EI < G->EndEI(); EI++) {
		EdgeH.AddKey(TIntPr(EI.GetSrcNId(), EI.GetDstNId()));
	}
	int Cnt = 0;
	for (TNGraph::TEdgeI EI = G->BegEI(); EI < G->EndEI(); EI++) {
		if (EdgeH.IsKey(TIntPr(EI.GetDstNId(), EI.GetSrcNId()))) { Cnt++; }
	}
	printf("Reciprocated edges: %d\n", Cnt/2);
  // zero in-degree and zero out-degree
  int ZeroIn=0, ZeroOut=0, TenOut=0, TenIn=0;
	for (TNGraph::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) {
		if (NI.GetOutDeg() == 0) { ZeroOut++; }
		if (NI.GetInDeg() == 0) { ZeroIn++; }
		if (NI.GetOutDeg() > 10) { TenOut++; }
		if (NI.GetInDeg() < 10) { TenIn++; }
	}
	printf("Zero out-degree nodes: %d\n", ZeroOut);
	printf("Zero in-degree nodes: %d\n", ZeroIn);
  printf("Out-degree > 10 nodes: %d\n", TenOut);
	printf("In-degree < 10 nodes: %d\n", TenIn);

  return 0;
}
