ผลต่างระหว่างรุ่นของ "01204212/friends"
ไปยังการนำทาง
ไปยังการค้นหา
Jittat (คุย | มีส่วนร่วม) (หน้าที่ถูกสร้างด้วย ': ''This part of 01204212'' == Code == <syntaxhighlight lang="java"> import java.io.BufferedReader; import java.io.InputStreamRead...') |
Jittat (คุย | มีส่วนร่วม) (→Code) |
||
แถว 10: | แถว 10: | ||
public class Main { | public class Main { | ||
− | + | public static void main(String[] args) { | |
− | + | Main main = new Main(); | |
− | + | ||
− | + | main.process(); | |
− | + | } | |
− | + | ||
− | + | int n,m; | |
− | + | List<Integer> [] adjList; | |
− | + | ||
− | + | void process() { | |
− | + | readInput(); | |
− | + | } | |
− | + | private void readInput() { | |
− | + | BufferedReader reader = new BufferedReader( | |
− | + | new InputStreamReader(System.in) ); | |
− | + | try { | |
− | + | String[] items = reader.readLine().split(" "); | |
− | + | n = Integer.parseInt(items[0]); | |
− | + | m = Integer.parseInt(items[1]); | |
− | + | adjList = (List<Integer>[])(new List[n]); | |
− | + | for(int i=0; i<n; i++) { | |
− | + | adjList[i] = new ArrayList<Integer>(); | |
− | + | } | |
− | + | ||
− | + | for(int i=0; i<m; i++) { | |
− | + | items = reader.readLine().split(" "); | |
− | + | int u = Integer.parseInt(items[0]) - 1; | |
− | + | int v = Integer.parseInt(items[1]) - 1; | |
− | + | ||
− | + | adjList[u].add(v); | |
− | + | adjList[v].add(u); | |
− | + | } | |
− | + | } catch(Exception e) { | |
− | + | } | |
− | + | } | |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
รุ่นแก้ไขเมื่อ 23:44, 23 พฤศจิกายน 2559
- This part of 01204212
Code
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
Main main = new Main();
main.process();
}
int n,m;
List<Integer> [] adjList;
void process() {
readInput();
}
private void readInput() {
BufferedReader reader = new BufferedReader(
new InputStreamReader(System.in) );
try {
String[] items = reader.readLine().split(" ");
n = Integer.parseInt(items[0]);
m = Integer.parseInt(items[1]);
adjList = (List<Integer>[])(new List[n]);
for(int i=0; i<n; i++) {
adjList[i] = new ArrayList<Integer>();
}
for(int i=0; i<m; i++) {
items = reader.readLine().split(" ");
int u = Integer.parseInt(items[0]) - 1;
int v = Integer.parseInt(items[1]) - 1;
adjList[u].add(v);
adjList[v].add(u);
}
} catch(Exception e) {
}
}
}