Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0a9978cb3
|
||
|
|
2820c84507 | ||
|
|
fbd41d8ac7
|
No files matched your search
@@ -0,0 +1,7 @@
|
||||
# NCPC26!!
|
||||
|
||||
This branch contains the code for NCPC 2026
|
||||
here we have 3 folder containing all problems
|
||||
- py: The python code
|
||||
- java: The java code
|
||||
- c: The c
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
@@ -0,0 +1,77 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int ship_x, ship_y;
|
||||
int treasure_x, treasure_y;
|
||||
int direction_x, direction_y;
|
||||
int movement_help;
|
||||
|
||||
scanf("%d %d", &ship_x, &ship_y);
|
||||
scanf("%d %d", &treasure_x, &treasure_y);
|
||||
|
||||
|
||||
|
||||
while (((ship_x == treasure_x) && (ship_y == treasure_y))==0){
|
||||
direction_x = ship_x - treasure_x;
|
||||
direction_y = ship_y - treasure_y;
|
||||
|
||||
//diagonal movement
|
||||
if (abs(direction_x) == abs(direction_y)){
|
||||
//NortEeast movment
|
||||
if((direction_x < 0) && (direction_y < 0)){
|
||||
printf("NE\n");
|
||||
ship_x -= direction_x;
|
||||
ship_y -= direction_y;
|
||||
}
|
||||
//NortWest movement
|
||||
else if((direction_x > 0) && (direction_y < 0)){
|
||||
printf("NW\n");
|
||||
ship_x -= direction_x;
|
||||
ship_y -= direction_y;
|
||||
}
|
||||
//SouthWest movement
|
||||
else if((direction_x > 0) && (direction_y > 0)){
|
||||
printf("SW\n");
|
||||
ship_x -= direction_x;
|
||||
ship_y -= direction_y;
|
||||
}
|
||||
//SouthEast movement
|
||||
else if((direction_x < 0) && (direction_y > 0)){
|
||||
printf("SE\n");
|
||||
ship_x -= direction_x;
|
||||
ship_y -= direction_y;
|
||||
}
|
||||
}
|
||||
else if((abs(direction_x) != abs(direction_y))){
|
||||
//horisontal / vertical movement
|
||||
if(abs(direction_x) > abs(direction_y)){
|
||||
movement_help = abs(abs(direction_x) - abs(direction_y));
|
||||
//East movement
|
||||
if(direction_x < 0){
|
||||
printf("E\n");
|
||||
ship_x += movement_help;
|
||||
}
|
||||
//West movement
|
||||
if(direction_x > 0){
|
||||
printf("W\n");
|
||||
ship_x -= movement_help;
|
||||
}
|
||||
}
|
||||
if(abs(direction_x) < abs(direction_y)){
|
||||
movement_help = abs( abs(direction_y) - abs(direction_x));
|
||||
//North Movement
|
||||
if(direction_y < 0){
|
||||
printf("N\n");
|
||||
ship_y += movement_help;
|
||||
}
|
||||
//South Movement
|
||||
if(direction_y > 0){
|
||||
printf("S\n");
|
||||
ship_y -= movement_help;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
Generated
-1
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
Generated
+1
-2
@@ -4,8 +4,7 @@
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="KubernetesApiProvider"><![CDATA[{}]]></component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="corretto-21" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
File renamed without changes.
File renamed without changes.
+2
-2
@@ -1,6 +1,6 @@
|
||||
#Sat Oct 04 11:03:43 CEST 2025
|
||||
#Sat Oct 03 11:00:43 CEST 2026
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
File renamed without changes.
Vendored
File renamed without changes.
@@ -0,0 +1 @@
|
||||
rootProject.name = 'java'
|
||||
@@ -0,0 +1,31 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class B {
|
||||
record Pair<K, V>(K key, V value)
|
||||
{}
|
||||
public static void main(String[] args) throws Exception {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
String input = br.readLine();
|
||||
int n = Integer.parseInt(input.split(" ")[0]);
|
||||
int k = Integer.parseInt(input.split(" ")[1]);
|
||||
int[] slots = new int[k];
|
||||
HashMap<String>
|
||||
for(int i = 0; i < n; i++)
|
||||
{
|
||||
input = br.readLine();
|
||||
int org = Integer.parseInt(input.split(" ")[0])-1;
|
||||
int dest = Integer.parseInt(input.split(" ")[1])-1;
|
||||
slots[org]--;
|
||||
slots[dest]++;
|
||||
}
|
||||
|
||||
long redudent = Arrays.stream(slots).filter((i) -> i == 0).count();
|
||||
|
||||
System.out.println(redudent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class D {
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
String spondee = "--";
|
||||
String trocha = "-u";
|
||||
String dactyl = "-uu";
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
String in = br.readLine();
|
||||
|
||||
int spondees = 0;
|
||||
int dactyls = 0;
|
||||
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
if(in.startsWith(spondee))
|
||||
{
|
||||
spondees++;
|
||||
in = in.substring(spondee.length());
|
||||
}
|
||||
else if(in.startsWith(dactyl))
|
||||
{
|
||||
dactyls++;
|
||||
in = in.substring(dactyl.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("no");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(!(spondees + dactyls == 5))
|
||||
{
|
||||
System.out.println("no");
|
||||
return;
|
||||
}
|
||||
if(in.length() > 2)
|
||||
{
|
||||
System.out.println("no");
|
||||
return;
|
||||
}
|
||||
if(!(in.endsWith(spondee) || in.endsWith(trocha)))
|
||||
{
|
||||
System.out.println("no");
|
||||
return;
|
||||
}
|
||||
System.out.println("yes");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class E {
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
char[][] nums = {
|
||||
// 0
|
||||
{
|
||||
'.', '#', '#', '.',
|
||||
'#', '.', '.', '#',
|
||||
'#', '.', '.', '#',
|
||||
'.', '.', '.', '.',
|
||||
'#', '.', '.', '#',
|
||||
'#', '.', '.', '#',
|
||||
'.', '#', '#', '.'
|
||||
},
|
||||
// 1
|
||||
{
|
||||
'.', '.', '.', '.',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '.',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '.'
|
||||
},
|
||||
// 2
|
||||
{
|
||||
'.', '#', '#', '.',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '#',
|
||||
'.', '#', '#', '.',
|
||||
'#', '.', '.', '.',
|
||||
'#', '.', '.', '.',
|
||||
'.', '#', '#', '.'
|
||||
},
|
||||
// 3
|
||||
{
|
||||
'.', '#', '#', '.',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '#',
|
||||
'.', '#', '#', '.',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '#',
|
||||
'.', '#', '#', '.'
|
||||
},
|
||||
// 4
|
||||
{
|
||||
'.', '.', '.', '.',
|
||||
'#', '.', '.', '#',
|
||||
'#', '.', '.', '#',
|
||||
'.', '#', '#', '.',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '.'
|
||||
},
|
||||
// 5
|
||||
{
|
||||
'.', '#', '#', '.',
|
||||
'#', '.', '.', '.',
|
||||
'#', '.', '.', '.',
|
||||
'.', '#', '#', '.',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '#',
|
||||
'.', '#', '#', '.'
|
||||
},
|
||||
// 6
|
||||
{
|
||||
'.', '#', '#', '.',
|
||||
'#', '.', '.', '.',
|
||||
'#', '.', '.', '.',
|
||||
'.', '#', '#', '.',
|
||||
'#', '.', '.', '#',
|
||||
'#', '.', '.', '#',
|
||||
'.', '#', '#', '.'
|
||||
},
|
||||
// 7
|
||||
{
|
||||
'.', '#', '#', '.',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '.',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '.'
|
||||
},
|
||||
// 8
|
||||
{
|
||||
'.', '#', '#', '.',
|
||||
'#', '.', '.', '#',
|
||||
'#', '.', '.', '#',
|
||||
'.', '#', '#', '.',
|
||||
'#', '.', '.', '#',
|
||||
'#', '.', '.', '#',
|
||||
'.', '#', '#', '.'
|
||||
},
|
||||
// 9
|
||||
{
|
||||
'.', '#', '#', '.',
|
||||
'#', '.', '.', '#',
|
||||
'#', '.', '.', '#',
|
||||
'.', '#', '#', '.',
|
||||
'.', '.', '.', '#',
|
||||
'.', '.', '.', '#',
|
||||
'.', '#', '#', '.'
|
||||
}
|
||||
};
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int i = 0; i < 7; i++)
|
||||
{
|
||||
sb.append(br.readLine());
|
||||
}
|
||||
|
||||
char[] input = sb.toString().toCharArray();
|
||||
|
||||
ArrayList<Integer> posibleNums = new ArrayList<>();
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
if(Arrays.equals(nums[i], input))
|
||||
{
|
||||
posibleNums.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
if(!posibleNums.isEmpty())
|
||||
{
|
||||
System.out.println(posibleNums.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i = 10; i < 100; i++)
|
||||
{
|
||||
char[] compiledNum = compileNum(nums, i);
|
||||
if(Arrays.equals(compiledNum, input))
|
||||
{
|
||||
posibleNums.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
if(posibleNums.isEmpty())
|
||||
{
|
||||
System.out.println("impossible");
|
||||
return;
|
||||
}
|
||||
|
||||
posibleNums.sort(Integer::compareTo);
|
||||
|
||||
sb = new StringBuilder();
|
||||
|
||||
StringBuilder finalSb = sb;
|
||||
posibleNums.forEach((i) -> {
|
||||
finalSb.append(i).append(" ");
|
||||
});
|
||||
String output = sb.toString().trim();
|
||||
System.out.println(output);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static char[] compileNum(char[][] nums, int i)
|
||||
{
|
||||
int tio = i / 10;
|
||||
int ett = i % 10;
|
||||
|
||||
char[] out = new char[28];
|
||||
|
||||
for(int j = 0; j < 28; j++)
|
||||
{
|
||||
out[j] = nums[tio][j] == nums[ett][j] ? '.' : '#';
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class I {
|
||||
public static void main(String[] args) throws Exception {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
String crewStr = br.readLine();
|
||||
String hermit1Str = br.readLine();
|
||||
String hermit2Str = br.readLine();
|
||||
String hermit3Str = br.readLine();
|
||||
int crew = Integer.parseInt(crewStr);
|
||||
int hermit1 = Integer.parseInt(hermit1Str);
|
||||
int hermit2 = Integer.parseInt(hermit2Str);
|
||||
int hermit3 = Integer.parseInt(hermit3Str);
|
||||
|
||||
ArrayList<Integer> hermits = new ArrayList<>();
|
||||
hermits.add(hermit1);
|
||||
hermits.add(hermit2);
|
||||
hermits.add(hermit3);
|
||||
|
||||
hermits.sort(Integer::compareTo);
|
||||
|
||||
if(hermits.get(0) + crew >= hermits.get(1))
|
||||
{
|
||||
System.out.println("impossible");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(hermits.get(0) + crew);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class K {
|
||||
|
||||
static record Pair<K, V>(K key, V value)
|
||||
{}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
int numTrees = Integer.parseInt(br.readLine());
|
||||
ArrayList<Pair<Integer, Integer>> trees = new ArrayList<>();
|
||||
for(int i = 0; i < numTrees; i++)
|
||||
{
|
||||
String str = br.readLine();
|
||||
int i1 = Integer.parseInt(str.split(" ")[0]);
|
||||
int i2 = Integer.parseInt(str.split(" ")[1]);
|
||||
trees.add(new Pair<>(i1, i2));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import sys
|
||||
|
||||
for line in sys.stdin:
|
||||
pices = int(line)
|
||||
|
||||
if (pices == 0):
|
||||
print(0)
|
||||
exit()
|
||||
|
||||
arr = list()
|
||||
arr = map(int, input().split())
|
||||
|
||||
ar = sorted(arr)
|
||||
|
||||
half = ar[pices-1] / 2
|
||||
|
||||
i = 0
|
||||
index = 0
|
||||
closest = 1001
|
||||
|
||||
if (pices == 1):
|
||||
print(ar[0])
|
||||
exit()
|
||||
|
||||
while ar[i] <= half:
|
||||
i += 1
|
||||
|
||||
if i > 0:
|
||||
if (ar[i] - half) <= closest:
|
||||
closest = (ar[i] - half)
|
||||
index = i
|
||||
if (half - ar[i-1]) <= closest:
|
||||
closest = (ar[i-1] - half)
|
||||
index = i-1
|
||||
else:
|
||||
index = 0
|
||||
|
||||
print(max((ar[pices-1] - ar[index]), ar[index]))
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
3
|
||||
400 199 201
|
||||
3
|
||||
400 202 199
|
||||
3
|
||||
400 201 198
|
||||
2
|
||||
500 100
|
||||
2
|
||||
101 99
|
||||
3
|
||||
100 100 100
|
||||
3
|
||||
100 200 300
|
||||
3
|
||||
1000 1 1
|
||||
3
|
||||
1000 500 100
|
||||
3
|
||||
100 101 99
|
||||
3
|
||||
100 150 50
|
||||
4
|
||||
200 400 200 100
|
||||
7
|
||||
100 100 900 500 500 1000 400
|
||||
@@ -0,0 +1,22 @@
|
||||
3
|
||||
401 600 1000
|
||||
3
|
||||
1 600 1000
|
||||
2
|
||||
1 2
|
||||
2
|
||||
1 1
|
||||
3
|
||||
1 1 2
|
||||
4
|
||||
1 2 1 1
|
||||
4
|
||||
1 2 2 1
|
||||
4
|
||||
1 2 2 2
|
||||
4
|
||||
400 1000 1000 1000
|
||||
5
|
||||
1000 1000 1000 998 22
|
||||
4
|
||||
300 500 150 100
|
||||
Whitespace-only changes.
@@ -1 +0,0 @@
|
||||
rootProject.name = 'NCPC-g'
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.kattis.ncpc26.p3.pending;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class A {
|
||||
public static void main(String[] args) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
int num = Integer.parseInt(reader.readLine());
|
||||
String s = reader.readLine();
|
||||
String[] nums = s.split(" ");
|
||||
for(int i = 1; i <= num; i++){
|
||||
if(!(nums[i-1].equals("mumble") || Integer.parseInt(nums[i-1]) == i))
|
||||
{
|
||||
System.out.println("something is fishy");
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.out.println("makes sense");
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
package com.kattis.ncpc26.p3.pending;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.*;
|
||||
|
||||
public class B {
|
||||
public static void main(String[] args) throws IOException {
|
||||
Map<Integer, Set<Integer>> exclusiveFollowing = new HashMap<>();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
String in = reader.readLine();
|
||||
int N = Integer.parseInt(in.split(" ")[0]);
|
||||
int M = Integer.parseInt(in.split(" ")[1]);
|
||||
for(int i = 0; i < M; i++)
|
||||
{
|
||||
in = reader.readLine();
|
||||
int u = Integer.parseInt(in.split(" ")[0]);
|
||||
int v = Integer.parseInt(in.split(" ")[1]);
|
||||
Set<Integer> followings = exclusiveFollowing.getOrDefault(v, new HashSet<>());
|
||||
followings.add(u);
|
||||
exclusiveFollowing.put(v, followings);
|
||||
}
|
||||
|
||||
ArrayList<Pair<Integer, Integer>> sortedFollowings = new ArrayList<>();
|
||||
|
||||
for(Map.Entry<Integer, Set<Integer>> user : exclusiveFollowing.entrySet())
|
||||
{
|
||||
int me = user.getKey();
|
||||
int likesMe = 0;
|
||||
for(int i : user.getValue())
|
||||
{
|
||||
if(!exclusiveFollowing.getOrDefault(i, new HashSet<>()).contains(me))
|
||||
{
|
||||
likesMe++;
|
||||
}
|
||||
}
|
||||
sortedFollowings.add(new Pair<>(me, likesMe));
|
||||
}
|
||||
|
||||
int mostFollowedUser = 1, followers = 0;
|
||||
for(Pair<Integer, Integer> user : sortedFollowings)
|
||||
{
|
||||
if(user.value > followers)
|
||||
{
|
||||
mostFollowedUser = user.key;
|
||||
followers = user.value;
|
||||
}
|
||||
else if(user.value == followers)
|
||||
{
|
||||
if(user.key < mostFollowedUser)
|
||||
{
|
||||
mostFollowedUser = user.key;
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.printf("%d %d", mostFollowedUser, followers);
|
||||
}
|
||||
|
||||
public static class Pair<K, V> {
|
||||
/**
|
||||
* The key of the pair.
|
||||
*/
|
||||
private K key;
|
||||
/**
|
||||
* The value of the pair.
|
||||
*/
|
||||
private V value;
|
||||
|
||||
/**
|
||||
* Creates a new instance of Pair.
|
||||
* @param key The key of the pair
|
||||
* @param value The value of the pair
|
||||
*/
|
||||
public Pair(K key, V value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key of the pair.
|
||||
* @return The key of the pair
|
||||
*/
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the pair.
|
||||
* @return The value of the pair
|
||||
*/
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the key of the pair.
|
||||
* @param key The key of the pair
|
||||
*/
|
||||
public void setKey(K key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the pair.
|
||||
* @param value The value of the pair
|
||||
*/
|
||||
public void setValue(V value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
package com.kattis.ncpc26.p3.pending;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.*;
|
||||
|
||||
public class D {
|
||||
public static void main(String[] args) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
String in;
|
||||
int num = 0;
|
||||
while(!(in = reader.readLine()).equals("0 0"))
|
||||
{
|
||||
Map<Integer, Set<Integer>> knownNumbers = new HashMap<>();
|
||||
int p = Integer.parseInt(in.split(" ")[0]);
|
||||
int c = Integer.parseInt(in.split(" ")[1]);
|
||||
if(p == 1)
|
||||
{
|
||||
System.out.println("No");
|
||||
continue;
|
||||
}
|
||||
for(int i = 0; i < c; i++)
|
||||
{
|
||||
in = reader.readLine();
|
||||
int a = Integer.parseInt(in.split(" ")[0]);
|
||||
int b = Integer.parseInt(in.split(" ")[1]);
|
||||
|
||||
if(!(a < p || b < p || a == b))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Set<Integer> numbersKnown = knownNumbers.getOrDefault(a, new HashSet<>());
|
||||
numbersKnown.add(b);
|
||||
knownNumbers.put(a, numbersKnown);
|
||||
|
||||
numbersKnown = knownNumbers.getOrDefault(b, new HashSet<>());
|
||||
numbersKnown.add(a);
|
||||
knownNumbers.put(b, numbersKnown);
|
||||
}
|
||||
|
||||
Set<Integer> reached = new HashSet<>();
|
||||
|
||||
ArrayList<Integer> toTraverse = new ArrayList<>();
|
||||
|
||||
toTraverse.add(0);
|
||||
|
||||
while(!toTraverse.isEmpty())
|
||||
{
|
||||
int node = toTraverse.getFirst();
|
||||
toTraverse.removeFirst();
|
||||
if(reached.contains(node)) continue;
|
||||
knownNumbers.getOrDefault(node, new HashSet<>()).forEach(
|
||||
(num1) -> {
|
||||
if(!toTraverse.contains(num1) && !reached.contains(num1))
|
||||
{
|
||||
toTraverse.add(num1);
|
||||
}
|
||||
}
|
||||
);
|
||||
reached.add(node);
|
||||
}
|
||||
|
||||
if(reached.size() < p)
|
||||
{
|
||||
System.out.println("Yes");
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean prematureExit = false;
|
||||
|
||||
for(Map.Entry<Integer, Set<Integer>> e : knownNumbers.entrySet())
|
||||
{
|
||||
if(e.getValue().size() <= 1)
|
||||
{
|
||||
System.out.println("Yes");
|
||||
prematureExit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!prematureExit)
|
||||
{
|
||||
System.out.println("No");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user