# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
736549 |
2023-05-05T22:44:39 Z |
rahulverma |
Network (BOI15_net) |
Java 11 |
|
159 ms |
11532 KB |
import java.io.*;
import java.util.*;
public class net {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
for(int i = 0; i < n; i++) graph.add(new ArrayList<Integer>());
for(int i = 1; i < n; i++) {
int v1 = s.nextInt() - 1;
int v2 = s.nextInt() - 1;
graph.get(v1).add(v2);
graph.get(v2).add(v1);
}
boolean found = true;
ArrayList<Integer> ans = new ArrayList<Integer>();
for(int i = 0; i < n; i++) {
if(graph.get(i).size() == 1) {
ans.add(i+1);
if(i == 0) found = true;
}
}
if(found) ans.add(1);
Collections.sort(ans, (a, b) -> (int) (System.currentTimeMillis()%2)*-1 + 1);
System.out.println((int) ans.size()/2);
for(int i = 0; i < ans.size()/2; i += 1) {
System.out.println(ans.get(2*i) + " " + ans.get(2*i + 1));
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
11384 KB |
Output is correct |
2 |
Correct |
143 ms |
11372 KB |
Output is correct |
3 |
Correct |
139 ms |
11300 KB |
Output is correct |
4 |
Correct |
155 ms |
11476 KB |
Output is correct |
5 |
Correct |
145 ms |
11532 KB |
Output is correct |
6 |
Correct |
139 ms |
11260 KB |
Output is correct |
7 |
Correct |
146 ms |
11264 KB |
Output is correct |
8 |
Correct |
140 ms |
11344 KB |
Output is correct |
9 |
Correct |
159 ms |
11328 KB |
Output is correct |
10 |
Incorrect |
149 ms |
11292 KB |
Breaking single line is causing network to disconnect. |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
11384 KB |
Output is correct |
2 |
Correct |
143 ms |
11372 KB |
Output is correct |
3 |
Correct |
139 ms |
11300 KB |
Output is correct |
4 |
Correct |
155 ms |
11476 KB |
Output is correct |
5 |
Correct |
145 ms |
11532 KB |
Output is correct |
6 |
Correct |
139 ms |
11260 KB |
Output is correct |
7 |
Correct |
146 ms |
11264 KB |
Output is correct |
8 |
Correct |
140 ms |
11344 KB |
Output is correct |
9 |
Correct |
159 ms |
11328 KB |
Output is correct |
10 |
Incorrect |
149 ms |
11292 KB |
Breaking single line is causing network to disconnect. |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
11384 KB |
Output is correct |
2 |
Correct |
143 ms |
11372 KB |
Output is correct |
3 |
Correct |
139 ms |
11300 KB |
Output is correct |
4 |
Correct |
155 ms |
11476 KB |
Output is correct |
5 |
Correct |
145 ms |
11532 KB |
Output is correct |
6 |
Correct |
139 ms |
11260 KB |
Output is correct |
7 |
Correct |
146 ms |
11264 KB |
Output is correct |
8 |
Correct |
140 ms |
11344 KB |
Output is correct |
9 |
Correct |
159 ms |
11328 KB |
Output is correct |
10 |
Incorrect |
149 ms |
11292 KB |
Breaking single line is causing network to disconnect. |
11 |
Halted |
0 ms |
0 KB |
- |