import java.io.*; import java.util.HashSet; import java.util.Set; /** * @author fishcanfly */ public class Main { public static void main(String[] args) throws IOException { // BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // String[] words = br.readLine().split("\\s"); // Scanner scanner = new Scanner(System.in); // int n = Integer.valueOf(words[0]); // int q = Integer.valueOf(words[1]);
//快速输入输出采用以下的方式
StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); in.nextToken(); int n = (int)in.nval; in.nextToken(); int q = (int)in.nval; int res = 0; Set<Integer>[] map = new HashSet[n+1]; for (int i = 1; i <= n; i++) { map[i] = new HashSet(); } for (int i = 1; i <= q; i++) { // words = br.readLine().split("\\s"); // int cas = Integer.valueOf(words[0]); in.nextToken(); int cas = (int)in.nval; switch (cas){ case 1: // int u = Integer.valueOf(words[1]); // int v = Integer.valueOf(words[2]); in.nextToken(); int u = (int)in.nval; in.nextToken(); int v = (int)in.nval; if( map[u].size() == 0){ res++; } if( map[v].size() == 0){ res++; } map[v].add(u); map[u].add(v); out.println(n-res); break; case 2: // v = Integer.valueOf(words[1]); in.nextToken(); v = (int)in.nval; for(Integer adj:map[v]){ if( map[adj].size() == 1){ res--; } map[adj].remove(v); } if(map[v].size() != 0){ res--; } map[v].clear(); out.println(n-res); break; default: break; } } out.flush(); // br.close(); } }
标签:atcoder,begin,JAVA,java,int,System,words,import,new From: https://www.cnblogs.com/fishcanfly/p/17434730.html