fork download
  1.  
  2. /*
  3.   * Author- Priyam Vora
  4.   * BTech 2nd Year DAIICT
  5.   */
  6.  
  7. /*
  8.  Eulerian Path is a path in graph that visits every edge exactly once.
  9.  Eulerian Circuit is an Eulerian Path which starts and ends on the same vertex.
  10.  Steps to check Euleran circuit or Path
  11.  1) All vertices with non-zero degree are connected.
  12.  We don’t care about vertices with zero degree because they don’t belong to Eulerian Cycle or Path
  13.  2) For Eulerian Path- If zero or two vertices have odd degree and all other vertices have even degree
  14.  For Eulerian Cycle- All vertices have even degree
  15.  */
  16. import java.io.*;
  17. import java.math.*;
  18. import java.util.*;
  19. import javax.print.attribute.SetOfIntegerSyntax;
  20.  
  21.  
  22.  
  23. public class Faltu{
  24. private static InputStream stream;
  25. private static byte[] buf = new byte[1024];
  26. private static int curChar;
  27. private static int numChars;
  28. private static SpaceCharFilter filter;
  29. private static PrintWriter pw;
  30.  
  31. public static void main(String[] args) {
  32. InputReader(System.in);
  33. pw = new PrintWriter(System.out);
  34. new Thread(null ,new Runnable(){
  35. public void run(){
  36. try{
  37. soln();
  38. pw.close();
  39. } catch(Exception e){
  40. e.printStackTrace();
  41. }
  42. }
  43. },"1",1<<26).start();
  44. }
  45.  
  46.  
  47.  
  48. //----------------------------------------My Code------------------------------------------------//
  49. static LinkedList<Integer> adj[];
  50. static boolean Visited[];
  51. static int deg[];
  52. static int V;
  53. private static void soln() {
  54. int cas=1;
  55. int t=nextInt();
  56. while(t-->0){
  57.  
  58. V=nextInt();
  59. int m=nextInt();
  60. buildGraph();
  61. for(int i=0;i<m;i++){
  62. int v=nextInt();
  63. int w=nextInt();
  64. adj[v].add(w);
  65. adj[w].add(v);
  66. deg[v]++;
  67. deg[w]++;
  68. }
  69.  
  70. if(isConnected() && isEulerian()==1){
  71. pw.println("Case "+cas+": Yes");
  72. }else{
  73. pw.println("Case "+cas+": No");
  74. }
  75. cas++;
  76.  
  77. }
  78. }
  79. //Check if condition-2 is satisfied
  80. private static int isEulerian(){
  81.  
  82. for(int i=1;i<=V;i++){
  83. if(adj[i].size()%2!=0){
  84. return 0;
  85. }
  86. }
  87. return 1;
  88.  
  89. //return 0;
  90. }
  91. // Check if the Graph is connected
  92. private static boolean isConnected(){
  93. dfs(1);
  94.  
  95. for(int i=1;i<=V;i++){
  96. if( Visited[i]==false)//check if every vertex with non zero degree is connected
  97. return false;
  98. }
  99. return true;
  100. }
  101. //Mark all the connected vertices true
  102. private static void dfs(int curr){
  103. Visited[curr]=true;
  104. for(int x:adj[curr]){
  105. if(!Visited[x])
  106. dfs(x);
  107. }
  108. }
  109.  
  110. private static void buildGraph(){
  111.  
  112. adj=new LinkedList[V+1];
  113. Visited=new boolean[V+1];
  114. deg=new int[V+1];
  115. for(int i=0;i<=V;i++){
  116. adj[i]=new LinkedList<Integer>();
  117. }
  118.  
  119. }
  120. //-----------------------------------------The End--------------------------------------------------------------------------//
  121.  
  122.  
  123. // To Get Input
  124. // Some Buffer Methods
  125.  
  126. public static void InputReader(InputStream stream1) {
  127. stream = stream1;
  128. }
  129.  
  130. private static boolean isWhitespace(int c) {
  131. return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  132. }
  133.  
  134. private static boolean isEndOfLine(int c) {
  135. return c == '\n' || c == '\r' || c == -1;
  136. }
  137.  
  138. private static int read() {
  139. if (numChars == -1)
  140. throw new InputMismatchException();
  141. if (curChar >= numChars) {
  142. curChar = 0;
  143. try {
  144. numChars = stream.read(buf);
  145. } catch (IOException e) {
  146. throw new InputMismatchException();
  147. }
  148. if (numChars <= 0)
  149. return -1;
  150. }
  151. return buf[curChar++];
  152. }
  153.  
  154. private static int nextInt() {
  155. int c = read();
  156. while (isSpaceChar(c))
  157. c = read();
  158. int sgn = 1;
  159. if (c == '-') {
  160. sgn = -1;
  161. c = read();
  162. }
  163. int res = 0;
  164. do {
  165. if (c < '0' || c > '9')
  166. throw new InputMismatchException();
  167. res *= 10;
  168. res += c - '0';
  169. c = read();
  170. } while (!isSpaceChar(c));
  171. return res * sgn;
  172. }
  173.  
  174. private static long nextLong() {
  175. int c = read();
  176. while (isSpaceChar(c))
  177. c = read();
  178. int sgn = 1;
  179. if (c == '-') {
  180. sgn = -1;
  181. c = read();
  182. }
  183. long res = 0;
  184. do {
  185. if (c < '0' || c > '9')
  186. throw new InputMismatchException();
  187. res *= 10;
  188. res += c - '0';
  189. c = read();
  190. } while (!isSpaceChar(c));
  191. return res * sgn;
  192. }
  193.  
  194. private static String nextToken() {
  195. int c = read();
  196. while (isSpaceChar(c))
  197. c = read();
  198. StringBuilder res = new StringBuilder();
  199. do {
  200. res.appendCodePoint(c);
  201. c = read();
  202. } while (!isSpaceChar(c));
  203. return res.toString();
  204. }
  205.  
  206. private static String nextLine() {
  207. int c = read();
  208. while (isSpaceChar(c))
  209. c = read();
  210. StringBuilder res = new StringBuilder();
  211. do {
  212. res.appendCodePoint(c);
  213. c = read();
  214. } while (!isEndOfLine(c));
  215. return res.toString();
  216. }
  217.  
  218. private static int[] nextIntArray(int n) {
  219. int[] arr = new int[n];
  220. for (int i = 0; i < n; i++) {
  221. arr[i] = nextInt();
  222. }
  223. return arr;
  224. }
  225.  
  226. private static int[][] next2dArray(int n, int m) {
  227. int[][] arr = new int[n][m];
  228. for (int i = 0; i < n; i++) {
  229. for (int j = 0; j < m; j++) {
  230. arr[i][j] = nextInt();
  231. }
  232. }
  233. return arr;
  234. }
  235. private static char[][] nextCharArray(int n,int m){
  236. char [][]c=new char[n][m];
  237. for(int i=0;i<n;i++){
  238. String s=nextLine();
  239. for(int j=0;j<s.length();j++){
  240. c[i][j]=s.charAt(j);
  241. }
  242. }
  243. return c;
  244. }
  245.  
  246. private static long[] nextLongArray(int n) {
  247. long[] arr = new long[n];
  248. for (int i = 0; i < n; i++) {
  249. arr[i] = nextLong();
  250. }
  251. return arr;
  252. }
  253.  
  254. private static void pArray(int[] arr) {
  255. for (int i = 0; i < arr.length; i++) {
  256. pw.print(arr[i] + " ");
  257. }
  258. pw.println();
  259. return;
  260. }
  261.  
  262. private static void pArray(long[] arr) {
  263. for (int i = 0; i < arr.length; i++) {
  264. pw.print(arr[i] + " ");
  265. }
  266. pw.println();
  267. return;
  268. }
  269.  
  270. private static void pArray(boolean[] arr) {
  271. for (int i = 0; i < arr.length; i++) {
  272. pw.print(arr[i] + " ");
  273. }
  274. pw.println();
  275. return;
  276. }
  277.  
  278. private static boolean isSpaceChar(int c) {
  279. if (filter != null)
  280. return filter.isSpaceChar(c);
  281. return isWhitespace(c);
  282. }
  283.  
  284. private interface SpaceCharFilter {
  285. public boolean isSpaceChar(int ch);
  286. }
  287. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:23: error: class Faltu is public, should be declared in a file named Faltu.java
    		    public class Faltu{
    		           ^
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
stdout
Standard output is empty