Guest User

Untitled

a guest
Aug 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.io.PrintWriter;
  6.  
  7. import java.util.HashSet;
  8. import java.util.Iterator;
  9. import java.util.LinkedList;
  10. import java.util.Map;
  11. import java.util.Queue;
  12. import java.util.StringTokenizer;
  13. import java.util.ArrayList;
  14. import java.util.TreeSet;
  15.  
  16. public class Main implements Runnable {
  17. StringTokenizer st;
  18. BufferedReader in;
  19. PrintWriter out;
  20. String s;
  21. int color[];
  22. Queue<Integer> Q;
  23. ArrayList<TreeSet<Character>>[] pr;
  24. static int POW = 'z' - 'a' + 2;
  25. int n, m, k;
  26. int cur = 0;
  27. TreeSet<Character> states;
  28. int ok[];
  29. int color2[];
  30. int leftsInUse[];
  31. char lefts[];
  32.  
  33.  
  34. // //////////////////////////////////////////////////////
  35. public static void main(String[] args) {
  36. new Thread(new Main()).start();
  37. }
  38. @SuppressWarnings("unchecked")
  39. void supMov(int a) {
  40. for (int k=0; k<pr[a].size(); k++) {
  41. Q.addAll((TreeSet)pr[a].get(k));
  42. }
  43. }
  44. public void run() {
  45. try {
  46. in = new BufferedReader(new FileReader("useless.in"));
  47. out = new PrintWriter(new FileWriter("useless.out"));
  48. solve();
  49. } catch (Exception e) {
  50. e.printStackTrace();
  51. System.exit(9000);
  52. } finally {
  53. out.flush();
  54. out.close();
  55. }
  56.  
  57. }
  58.  
  59. String nextToken() throws IOException {
  60. while (st == null || !st.hasMoreTokens()) {
  61. st = new StringTokenizer(in.readLine());
  62. }
  63. return st.nextToken();
  64. }
  65.  
  66. int nextInt() throws NumberFormatException, IOException {
  67. return Integer.parseInt(nextToken());
  68. }
  69.  
  70. long nextLong() throws NumberFormatException, IOException {
  71. return Long.parseLong(nextToken());
  72. }
  73.  
  74. double nextDouble() throws NumberFormatException, IOException {
  75. return Double.parseDouble(nextToken());
  76. }
  77.  
  78. @SuppressWarnings("unchecked")
  79. void solve() throws NumberFormatException, IOException {
  80. n = nextInt();
  81. pr=new ArrayList[POW];
  82. ok=new int[POW];
  83. for (int i=0; i<POW; i++) pr[i]=new ArrayList<TreeSet<Character>>();
  84.  
  85.  
  86. color=new int[POW];
  87. color2=new int[POW];
  88.  
  89. char start = (char) (nextToken().charAt(0)-'A');
  90. for (int i = 0; i < n; i++) {
  91. char t = (char) (nextToken().charAt(0)-'A');
  92. String s = nextToken();
  93. color2[t]=1;
  94. if (st.hasMoreTokens()) {
  95. s = nextToken();
  96. TreeSet<Character> T= new TreeSet();
  97. char let[] = s.toCharArray();
  98. for (char c : let) {
  99. if ((c>='A')&&(c<='Z'))
  100. T.add(c);
  101. }
  102. pr[t].add(T);
  103. } else {
  104. TreeSet<Character> T = new TreeSet();
  105.  
  106. T.add('@');
  107. pr[t].add(T);
  108.  
  109.  
  110. }
  111.  
  112. }
  113. Q=new LinkedList();
  114. Q.add((int)start);
  115. color[start]=1;
  116. while(!Q.isEmpty()) {
  117. int a= Q.remove();
  118. if (color[a]!=1){
  119. supMov(a);
  120. color[a]=1;
  121. }
  122. }
  123. for (int i=1; i<POW; i++) {
  124. if ((color[i]==0)&&(color2[i]!=0)) out.print((char)(i+'A'-1)+" ");
  125. }
  126.  
  127.  
  128. }
  129. }
Add Comment
Please, Sign In to add comment