제출 #283524

#제출 시각아이디문제언어결과실행 시간메모리
283524ijxjdjdNetwork (BOI15_net)Java
컴파일 에러
0 ms0 KiB
public class net { ArrayList<Integer>[] adj; public static void main(String[] args) { try { Reader r = new Reader(); int N = r.nextInt(); adj = new ArrayList[N]; for (int i = 0; i < N; i++) { adj[i] = new ArrayList<>(); } for (int i = 0; i < N - 1; i++) { int a = r.nextInt() - 1; int b = r.nextInt() - 1; adj[a].add(b); adj[b].add(a); } if (N == 2) { out.println("1\n1 2"); } else { for (int i = 0; i < N; i++) { if (adj[i].size() > 1) { Set f = dfs(i); if (f.a2 == -1) { ans.add(new Set(f.a1, i)); } else { ans.add(new Set(f.a1, f.a2)); } break; } } System.out.println(ans.size()); for (Set s : ans) { System.out.println((s.a1 + 1) + " " + (s.a2 + 1)); } } } catch (IOException e) { } } ArrayList<Set> ans = new ArrayList<>(); Set dfs(int n) { Stack<State> stack = new Stack<>(); stack.add(new State(n, n)); while (stack.size() > 0) { State next = stack.peek(); int a = next.getNext(); if (a == -1) { stack.pop(); if (stack.isEmpty()) { return next.s; } if (next.cur == 1) { stack.peek().merge(new Set(next.n)); } else { stack.peek().merge(next.s); } } else { stack.add(new State(a, next.n)); } } return null; } class State { int cur; int n; int p; Set s = null; State(int n, int p) { cur = 0; this.n = n; this.p = p; } int getNext() { if (cur >= adj[n].size()) { return -1; } else if (adj[n].get(cur) == p) { cur++; return getNext(); } else { return adj[n].get(cur++); } } void merge(Set s) { if (this.s == null) { this.s = s; } else { this.s.merge(s); } } } class Set { int a1; int a2; void merge(Set s) { if (s.a2 == -1 && this.a2 == -1) { this.a2 = s.a1; } else if (s.a2 == -1){ ans.add(new Set(s.a1, this.a2)); this.a2 = -1; } else if (this.a2 == -1){ ans.add(new Set(this.a1, s.a2)); this.a1 = s.a1; } else { ans.add(new Set(this.a1, s.a1)); this.a1 = this.a2; this.a2 = s.a2; } } Set(int a) { this.a1 = a; this.a2 = -1; } Set(int a, int b) { this.a1 = a; this.a2 = b; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } } }

컴파일 시 표준 에러 (stderr) 메시지

net.java:2: error: cannot find symbol
  ArrayList<Integer>[] adj;
  ^
  symbol:   class ArrayList
  location: class net
net.java:41: error: cannot find symbol
    ArrayList<Set> ans = new ArrayList<>();
    ^
  symbol:   class ArrayList
  location: class net
net.java:129: error: cannot find symbol
        private DataInputStream din;
                ^
  symbol:   class DataInputStream
  location: class Reader
net.java:140: error: cannot find symbol
        public Reader(String file_name) throws IOException
                                               ^
  symbol:   class IOException
  location: class Reader
net.java:147: error: cannot find symbol
        public String readLine() throws IOException
                                        ^
  symbol:   class IOException
  location: class Reader
net.java:160: error: cannot find symbol
        public int nextInt() throws IOException
                                    ^
  symbol:   class IOException
  location: class Reader
net.java:179: error: cannot find symbol
        public long nextLong() throws IOException
                                      ^
  symbol:   class IOException
  location: class Reader
net.java:197: error: cannot find symbol
        public double nextDouble() throws IOException
                                          ^
  symbol:   class IOException
  location: class Reader
net.java:225: error: cannot find symbol
        private void fillBuffer() throws IOException
                                         ^
  symbol:   class IOException
  location: class Reader
net.java:232: error: cannot find symbol
        private byte read() throws IOException
                                   ^
  symbol:   class IOException
  location: class Reader
net.java:7: error: non-static variable adj cannot be referenced from a static context
            adj = new ArrayList[N];
            ^
net.java:7: error: cannot find symbol
            adj = new ArrayList[N];
                      ^
  symbol:   class ArrayList
  location: class net
net.java:9: error: non-static variable adj cannot be referenced from a static context
                adj[i] = new ArrayList<>();
                ^
net.java:9: error: cannot find symbol
                adj[i] = new ArrayList<>();
                             ^
  symbol:   class ArrayList
  location: class net
net.java:14: error: non-static variable adj cannot be referenced from a static context
                adj[a].add(b);
                ^
net.java:15: error: non-static variable adj cannot be referenced from a static context
                adj[b].add(a);
                ^
net.java:18: error: cannot find symbol
                out.println("1\n1 2");
                ^
  symbol:   variable out
  location: class net
net.java:21: error: non-static variable adj cannot be referenced from a static context
                    if (adj[i].size() > 1) {
                        ^
net.java:22: error: non-static method dfs(int) cannot be referenced from a static context
                        Set f = dfs(i);
                                ^
net.java:24: error: non-static variable this cannot be referenced from a static context
                            ans.add(new Set(f.a1, i));
                                    ^
net.java:24: error: non-static variable ans cannot be referenced from a static context
                            ans.add(new Set(f.a1, i));
                            ^
net.java:26: error: non-static variable this cannot be referenced from a static context
                            ans.add(new Set(f.a1, f.a2));
                                    ^
net.java:26: error: non-static variable ans cannot be referenced from a static context
                            ans.add(new Set(f.a1, f.a2));
                            ^
net.java:31: error: non-static variable ans cannot be referenced from a static context
                System.out.println(ans.size());
                                   ^
net.java:32: error: non-static variable ans cannot be referenced from a static context
                for (Set s : ans) {
                             ^
net.java:37: error: cannot find symbol
        catch (IOException e) {
               ^
  symbol:   class IOException
  location: class net
net.java:41: error: cannot find symbol
    ArrayList<Set> ans = new ArrayList<>();
                             ^
  symbol:   class ArrayList
  location: class net
net.java:43: error: cannot find symbol
        Stack<State> stack = new Stack<>();
        ^
  symbol:   class Stack
  location: class net
net.java:43: error: cannot find symbol
        Stack<State> stack = new Stack<>();
                                 ^
  symbol:   class Stack
  location: class net
net.java:135: error: cannot find symbol
            din = new DataInputStream(System.in);
                      ^
  symbol:   class DataInputStream
  location: class Reader
net.java:142: error: cannot find symbol
            din = new DataInputStream(new FileInputStream(file_name));
                      ^
  symbol:   class DataInputStream
  location: class Reader
net.java:142: error: cannot find symbol
            din = new DataInputStream(new FileInputStream(file_name));
                                          ^
  symbol:   class FileInputStream
  location: class Reader
32 errors