fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static class BDD {
  11. static final BDD TRUE = new BDD();
  12. static final BDD FALSE = new BDD();
  13. BDD trueC, falseC;
  14. String v;
  15.  
  16. boolean isDAG(){
  17. return isDAG(new HashSet<BDD>());
  18. }
  19.  
  20. boolean isDAG(HashSet<BDD> p) {
  21. if (p.contains(this)) {
  22. return false;
  23. }
  24. p.add(this);
  25. boolean ret = (trueC == null || trueC.isDAG(p)) && (falseC == null || falseC.isDAG(p));
  26. p.remove(this);
  27. return ret;
  28. }
  29. }
  30.  
  31. public static void main (String[] args) throws java.lang.Exception
  32. {
  33. // b=TRUE <-- a <-- c
  34. // a is not the root of the DAG!
  35. BDD a = new BDD();
  36. BDD b = BDD.TRUE;
  37. BDD c = new BDD();
  38. c.trueC = a;
  39.  
  40. a.v = "a";
  41. c.v = "c";
  42. System.out.println("b=TRUE <-- a <-- c: failed? " + (a.isDAG() ? "yes" : "no"));
  43. }
  44. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
b=TRUE <-- a <-- c: failed? yes