diff --git a/README.md b/README.md index ab7b127..7924239 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ Repositório com a formatação de problemas que exploram variadas técnicas de - [Knight Moves](./knight-moves) - [Sliding Puzzle](./sliding-puzzle) - [Lazy Jumping Frog](./ra-preguicosa/) +- [Rede Anel Estelar](./rede-anel-estelar/) --- diff --git a/rede-anel-estelar/Makefile b/rede-anel-estelar/Makefile new file mode 100644 index 0000000..4227f1a --- /dev/null +++ b/rede-anel-estelar/Makefile @@ -0,0 +1,97 @@ +# Normal directories +SRC_DIR := src +BIN_DIR := bin +DBG_DIR := bin/debug + +# Grader directories +GRADER := $(wildcard $(SRC_DIR)/grader.cpp) +GRADER_DIR := $(SRC_DIR)/grader +HANDLER_DIR := $(SRC_DIR)/handler + +GRADER_SRC := $(wildcard $(GRADER_DIR)/*.cpp) +GRADER_BIN := $(patsubst $(GRADER_DIR)/%.cpp, $(BIN_DIR)/%, $(GRADER_SRC)) +GRADER_DBG := $(patsubst $(GRADER_DIR)/%.cpp, $(DBG_DIR)/%, $(GRADER_SRC)) + +# Change CPP source directories if grader is defined +ifdef GRADER + SRC := $(wildcard $(HANDLER_DIR)/*.cpp) + BIN := $(patsubst $(HANDLER_DIR)/%.cpp, $(BIN_DIR)/%, $(SRC)) + DBG := $(patsubst $(HANDLER_DIR)/%.cpp, $(DBG_DIR)/%, $(SRC)) +else + SRC := $(wildcard $(SRC_DIR)/*.cpp) + BIN := $(patsubst $(SRC_DIR)/%.cpp, $(BIN_DIR)/%, $(SRC)) + DBG := $(patsubst $(SRC_DIR)/%.cpp, $(DBG_DIR)/%, $(SRC)) +endif + +SRC_C := $(wildcard $(SRC_DIR)/*.c) +BIN_C := $(patsubst $(SRC_DIR)/%.c, $(BIN_DIR)/%, $(SRC_C)) +DBG_C := $(patsubst $(SRC_DIR)/%.c, $(DBG_DIR)/%, $(SRC_C)) + +SRC_JAVA := $(wildcard $(SRC_DIR)/*.java) +BIN_JAVA := $(patsubst $(SRC_DIR)/%.java, $(BIN_DIR)/%.class, $(SRC_JAVA)) +DBG_JAVA := $(patsubst $(SRC_DIR)/%.java, $(DBG_DIR)/%.class, $(SRC_JAVA)) + +CHECKER := $(wildcard $(SRC_DIR)/checker.cpp) + +C := gcc +CPP := g++ +CXX_FLAGS := -Wall -O2 +DEBUG_FLAGS := -Wall -g +BOCA_FLAGS := -static -DBOCA_SUPPORT + +JV = javac +JV_DEBUG = -g +JV_DIR = -d bin +JV_DBG_DIR = -d bin/debug + +.PHONY: all debug release checker clean + +all: debug release checker + +debug: $(DBG) $(DBG_C) $(DBG_JAVA) $(GRADER_DBG) + +release: $(BIN) $(BIN_C) $(BIN_JAVA) $(GRADER_BIN) + +ifdef CHECKER +checker: $(DBG_DIR)/checker-boca $(BIN_DIR)/checker-boca +endif + +$(BIN): $(BIN_DIR)/% : $(SRC_DIR)/%.cpp | $(BIN_DIR) + $(CPP) $(CXX_FLAGS) $^ -o $@ + +$(DBG): $(DBG_DIR)/% : $(SRC_DIR)/%.cpp | $(DBG_DIR) + $(CPP) $(DEBUG_FLAGS) $^ -o $@ + +$(BIN_C): $(BIN_DIR)/% : $(SRC_DIR)/%.c | $(BIN_DIR) + $(C) $(CXX_FLAGS) $^ -o $@ + +$(DBG_C): $(DBG_DIR)/% : $(SRC_DIR)/%.c | $(DBG_DIR) + $(C) $(DEBUG_FLAGS) $^ -o $@ + +$(BIN_JAVA): $(BIN_DIR)/%.class : $(SRC_DIR)/%.java | $(BIN_DIR) + $(JV) $(JV_DIR) $^ + +$(DBG_JAVA): $(DBG_DIR)/%.class : $(SRC_DIR)/%.java | $(DBG_DIR) + $(JV) $(JV_DEBUG) $(JV_DBG_DIR) $^ + +$(GRADER_BIN): $(BIN_DIR)/% : $(GRADER_DIR)/%.cpp $(GRADER) $(GRADER_DIR)/*.h + $(CPP) $(CXX_FLAGS) $^ -o $@ + +$(GRADER_DBG): $(DBG_DIR)/% : $(GRADER_DIR)/%.cpp $(GRADER) $(GRADER_DIR)/*.h + $(CPP) $(DEBUG_FLAGS) $^ -o $@ + +$(BIN_DIR): + mkdir -p $@ + +$(DBG_DIR): + mkdir -p $@ + +$(BIN_DIR)/checker-boca: $(SRC_DIR)/checker.cpp + $(CPP) $(CXX_FLAGS) $(BOCA_FLAGS) $^ -o $@ + +$(DBG_DIR)/checker-boca: $(SRC_DIR)/checker.cpp + $(CPP) $(DEBUG_FLAGS) $(BOCA_FLAGS) $^ -o $@ + +clean: + @echo Cleaning problem files + rm -rf bin diff --git a/rede-anel-estelar/image.png b/rede-anel-estelar/image.png new file mode 100644 index 0000000..12a430a Binary files /dev/null and b/rede-anel-estelar/image.png differ diff --git a/rede-anel-estelar/input/1 b/rede-anel-estelar/input/1 new file mode 100644 index 0000000..31436a9 --- /dev/null +++ b/rede-anel-estelar/input/1 @@ -0,0 +1,15 @@ +14 14 +10 1 +10 7 +3 8 +10 13 +13 7 +12 5 +8 2 +2 13 +14 1 +9 1 +11 4 +12 4 +4 7 +6 8 diff --git a/rede-anel-estelar/input/10 b/rede-anel-estelar/input/10 new file mode 100644 index 0000000..e938a0e --- /dev/null +++ b/rede-anel-estelar/input/10 @@ -0,0 +1,8 @@ +7 7 +3 2 +4 7 +4 2 +5 7 +6 5 +5 1 +1 3 diff --git a/rede-anel-estelar/input/100 b/rede-anel-estelar/input/100 new file mode 100644 index 0000000..79a8549 --- /dev/null +++ b/rede-anel-estelar/input/100 @@ -0,0 +1,37 @@ +36 36 +30 23 +3 10 +26 7 +32 31 +5 25 +36 30 +4 2 +27 34 +2 23 +28 30 +36 33 +5 14 +19 36 +35 20 +12 24 +31 1 +7 15 +8 27 +22 26 +25 24 +15 16 +10 18 +6 29 +13 25 +11 31 +9 10 +7 25 +31 36 +10 21 +29 17 +25 30 +8 33 +7 20 +29 8 +8 14 +10 5 diff --git a/rede-anel-estelar/input/101 b/rede-anel-estelar/input/101 new file mode 100644 index 0000000..4767aa8 --- /dev/null +++ b/rede-anel-estelar/input/101 @@ -0,0 +1,43 @@ +42 42 +33 8 +10 38 +29 14 +32 3 +29 19 +39 32 +1 11 +6 31 +12 20 +36 27 +26 34 +9 16 +24 37 +3 35 +30 26 +33 22 +17 12 +5 1 +27 5 +19 4 +14 18 +2 41 +40 11 +36 13 +2 38 +40 35 +34 25 +24 31 +7 39 +42 41 +37 23 +17 7 +30 9 +10 8 +13 28 +42 25 +15 22 +23 28 +18 21 +16 21 +6 20 +15 4 diff --git a/rede-anel-estelar/input/102 b/rede-anel-estelar/input/102 new file mode 100644 index 0000000..194d36b --- /dev/null +++ b/rede-anel-estelar/input/102 @@ -0,0 +1,37 @@ +36 36 +29 11 +31 13 +27 14 +16 3 +25 6 +30 35 +34 17 +32 25 +8 9 +36 19 +14 15 +5 11 +33 35 +2 33 +3 30 +26 29 +10 23 +12 31 +10 4 +15 34 +4 18 +27 7 +17 21 +5 24 +8 20 +26 7 +23 36 +9 16 +12 24 +13 32 +6 21 +18 2 +28 22 +20 1 +22 1 +19 28 diff --git a/rede-anel-estelar/input/103 b/rede-anel-estelar/input/103 new file mode 100644 index 0000000..ccfb7ee --- /dev/null +++ b/rede-anel-estelar/input/103 @@ -0,0 +1,57 @@ +56 56 +24 37 +35 27 +16 55 +34 7 +3 41 +24 18 +31 28 +27 5 +54 29 +32 26 +50 38 +47 3 +36 25 +14 48 +36 44 +44 14 +28 8 +25 6 +23 2 +33 39 +46 47 +7 9 +17 42 +9 11 +49 34 +20 39 +5 56 +45 46 +42 37 +31 21 +22 32 +38 53 +29 4 +46 52 +35 22 +20 43 +16 19 +15 13 +15 10 +26 54 +30 45 +18 25 +53 40 +51 43 +30 10 +49 2 +21 4 +40 8 +23 13 +51 56 +15 12 +44 1 +17 55 +48 33 +19 11 +50 41 diff --git a/rede-anel-estelar/input/104 b/rede-anel-estelar/input/104 new file mode 100644 index 0000000..90f4ee7 --- /dev/null +++ b/rede-anel-estelar/input/104 @@ -0,0 +1,94 @@ +94 93 +61 46 +15 10 +72 80 +80 13 +57 47 +53 59 +85 26 +25 67 +87 32 +61 4 +64 66 +15 36 +42 82 +43 61 +51 29 +45 92 +13 85 +94 43 +75 5 +5 48 +60 68 +50 92 +64 58 +90 37 +86 80 +20 23 +15 24 +63 42 +61 81 +3 54 +2 17 +67 80 +82 2 +39 44 +69 82 +36 82 +80 68 +1 68 +82 58 +18 35 +84 5 +49 22 +2 11 +55 26 +83 27 +37 41 +62 34 +37 56 +44 31 +82 83 +61 47 +35 17 +12 56 +24 91 +8 32 +13 47 +92 66 +79 9 +16 32 +32 51 +8 84 +8 3 +2 37 +13 82 +21 59 +26 6 +53 33 +19 29 +22 62 +31 76 +74 61 +21 62 +54 52 +36 89 +88 17 +30 73 +93 70 +3 7 +65 89 +38 69 +81 20 +13 53 +17 9 +77 16 +71 29 +14 18 +85 78 +30 5 +32 82 +47 93 +16 31 +68 40 +28 67 diff --git a/rede-anel-estelar/input/105 b/rede-anel-estelar/input/105 new file mode 100644 index 0000000..14b7a53 --- /dev/null +++ b/rede-anel-estelar/input/105 @@ -0,0 +1,101 @@ +100 100 +51 98 +14 74 +59 57 +63 21 +72 46 +54 18 +37 96 +60 25 +42 100 +12 24 +34 46 +45 82 +90 91 +95 92 +33 96 +37 6 +94 51 +33 83 +19 29 +88 17 +7 65 +39 76 +76 26 +93 55 +61 58 +22 19 +90 14 +46 36 +94 67 +28 20 +38 7 +49 21 +27 56 +45 68 +80 78 +21 65 +1 96 +54 4 +17 16 +74 37 +80 6 +35 33 +48 1 +51 69 +93 82 +71 84 +54 30 +57 95 +31 15 +1 2 +75 37 +13 9 +95 52 +75 44 +82 7 +57 89 +53 60 +21 84 +27 43 +76 99 +77 10 +13 26 +32 23 +40 39 +50 54 +89 67 +53 95 +88 35 +66 22 +16 25 +94 86 +87 11 +85 100 +40 64 +58 47 +87 89 +6 5 +81 31 +79 57 +58 62 +34 85 +8 71 +84 40 +80 81 +31 10 +94 66 +100 58 +37 3 +44 24 +72 93 +23 37 +27 17 +33 41 +97 71 +31 85 +20 22 +73 30 +79 70 +28 76 +26 54 diff --git a/rede-anel-estelar/input/11 b/rede-anel-estelar/input/11 new file mode 100644 index 0000000..d9037f1 --- /dev/null +++ b/rede-anel-estelar/input/11 @@ -0,0 +1,5 @@ +5 4 +5 2 +2 4 +2 1 +4 3 diff --git a/rede-anel-estelar/input/12 b/rede-anel-estelar/input/12 new file mode 100644 index 0000000..56eea14 --- /dev/null +++ b/rede-anel-estelar/input/12 @@ -0,0 +1,6 @@ +5 5 +2 1 +4 3 +5 3 +4 1 +2 5 diff --git a/rede-anel-estelar/input/13 b/rede-anel-estelar/input/13 new file mode 100644 index 0000000..781f694 --- /dev/null +++ b/rede-anel-estelar/input/13 @@ -0,0 +1,8 @@ +7 7 +5 6 +3 4 +5 2 +1 2 +2 7 +2 4 +7 6 diff --git a/rede-anel-estelar/input/14 b/rede-anel-estelar/input/14 new file mode 100644 index 0000000..3111349 --- /dev/null +++ b/rede-anel-estelar/input/14 @@ -0,0 +1,7 @@ +6 6 +6 2 +5 6 +2 5 +1 3 +3 4 +1 4 diff --git a/rede-anel-estelar/input/15 b/rede-anel-estelar/input/15 new file mode 100644 index 0000000..b8124c4 --- /dev/null +++ b/rede-anel-estelar/input/15 @@ -0,0 +1,5 @@ +4 4 +2 3 +4 3 +4 1 +1 2 diff --git a/rede-anel-estelar/input/16 b/rede-anel-estelar/input/16 new file mode 100644 index 0000000..6475a78 --- /dev/null +++ b/rede-anel-estelar/input/16 @@ -0,0 +1,4 @@ +4 3 +2 3 +4 3 +1 4 diff --git a/rede-anel-estelar/input/17 b/rede-anel-estelar/input/17 new file mode 100644 index 0000000..d5b3677 --- /dev/null +++ b/rede-anel-estelar/input/17 @@ -0,0 +1,11 @@ +5 10 +4 2 +4 3 +1 3 +1 5 +5 2 +3 5 +2 1 +2 3 +1 4 +5 4 diff --git a/rede-anel-estelar/input/18 b/rede-anel-estelar/input/18 new file mode 100644 index 0000000..e32176d --- /dev/null +++ b/rede-anel-estelar/input/18 @@ -0,0 +1,8 @@ +7 7 +2 5 +5 4 +6 5 +5 7 +1 4 +6 4 +3 1 diff --git a/rede-anel-estelar/input/19 b/rede-anel-estelar/input/19 new file mode 100644 index 0000000..1c4f583 --- /dev/null +++ b/rede-anel-estelar/input/19 @@ -0,0 +1,8 @@ +7 7 +7 4 +2 3 +3 7 +6 1 +5 4 +5 1 +2 6 diff --git a/rede-anel-estelar/input/2 b/rede-anel-estelar/input/2 new file mode 100644 index 0000000..f09576b --- /dev/null +++ b/rede-anel-estelar/input/2 @@ -0,0 +1,4 @@ +3 3 +2 3 +1 3 +1 2 diff --git a/rede-anel-estelar/input/20 b/rede-anel-estelar/input/20 new file mode 100644 index 0000000..5c5eb20 --- /dev/null +++ b/rede-anel-estelar/input/20 @@ -0,0 +1,9 @@ +8 8 +6 5 +8 3 +8 7 +3 4 +5 1 +2 8 +2 6 +1 4 diff --git a/rede-anel-estelar/input/21 b/rede-anel-estelar/input/21 new file mode 100644 index 0000000..1149d16 --- /dev/null +++ b/rede-anel-estelar/input/21 @@ -0,0 +1,12 @@ +6 11 +2 3 +1 5 +4 6 +3 4 +6 5 +6 1 +1 2 +5 4 +1 3 +5 3 +5 2 diff --git a/rede-anel-estelar/input/22 b/rede-anel-estelar/input/22 new file mode 100644 index 0000000..06b1358 --- /dev/null +++ b/rede-anel-estelar/input/22 @@ -0,0 +1,5 @@ +4 4 +1 4 +3 4 +2 3 +1 2 diff --git a/rede-anel-estelar/input/23 b/rede-anel-estelar/input/23 new file mode 100644 index 0000000..a4cfd17 --- /dev/null +++ b/rede-anel-estelar/input/23 @@ -0,0 +1,8 @@ +7 7 +3 6 +2 7 +2 6 +5 1 +4 5 +1 4 +3 7 diff --git a/rede-anel-estelar/input/24 b/rede-anel-estelar/input/24 new file mode 100644 index 0000000..d89bd24 --- /dev/null +++ b/rede-anel-estelar/input/24 @@ -0,0 +1,8 @@ +7 7 +6 4 +1 3 +5 7 +2 6 +4 2 +7 3 +5 1 diff --git a/rede-anel-estelar/input/25 b/rede-anel-estelar/input/25 new file mode 100644 index 0000000..a0a4dad --- /dev/null +++ b/rede-anel-estelar/input/25 @@ -0,0 +1,8 @@ +7 7 +2 6 +4 5 +7 4 +1 7 +3 5 +5 2 +2 1 diff --git a/rede-anel-estelar/input/26 b/rede-anel-estelar/input/26 new file mode 100644 index 0000000..fb0d987 --- /dev/null +++ b/rede-anel-estelar/input/26 @@ -0,0 +1,7 @@ +6 6 +3 5 +2 5 +6 4 +2 4 +6 3 +3 1 diff --git a/rede-anel-estelar/input/27 b/rede-anel-estelar/input/27 new file mode 100644 index 0000000..0ec48a0 --- /dev/null +++ b/rede-anel-estelar/input/27 @@ -0,0 +1,7 @@ +6 6 +5 6 +1 5 +4 3 +2 3 +2 4 +6 1 diff --git a/rede-anel-estelar/input/28 b/rede-anel-estelar/input/28 new file mode 100644 index 0000000..92523c1 --- /dev/null +++ b/rede-anel-estelar/input/28 @@ -0,0 +1,9 @@ +8 8 +5 7 +4 1 +4 7 +5 1 +8 3 +2 3 +8 6 +2 6 diff --git a/rede-anel-estelar/input/29 b/rede-anel-estelar/input/29 new file mode 100644 index 0000000..a292fd6 --- /dev/null +++ b/rede-anel-estelar/input/29 @@ -0,0 +1,3 @@ +3 2 +1 3 +2 3 diff --git a/rede-anel-estelar/input/3 b/rede-anel-estelar/input/3 new file mode 100644 index 0000000..09c9b38 --- /dev/null +++ b/rede-anel-estelar/input/3 @@ -0,0 +1,4 @@ +4 3 +3 1 +4 2 +1 2 diff --git a/rede-anel-estelar/input/30 b/rede-anel-estelar/input/30 new file mode 100644 index 0000000..d6ee909 --- /dev/null +++ b/rede-anel-estelar/input/30 @@ -0,0 +1,7 @@ +6 6 +3 2 +4 5 +6 5 +2 1 +3 5 +6 1 diff --git a/rede-anel-estelar/input/31 b/rede-anel-estelar/input/31 new file mode 100644 index 0000000..b4465e1 --- /dev/null +++ b/rede-anel-estelar/input/31 @@ -0,0 +1,9 @@ +8 8 +4 5 +2 6 +4 3 +8 7 +5 8 +1 2 +7 6 +1 3 diff --git a/rede-anel-estelar/input/32 b/rede-anel-estelar/input/32 new file mode 100644 index 0000000..57ac44d --- /dev/null +++ b/rede-anel-estelar/input/32 @@ -0,0 +1,4 @@ +3 3 +1 3 +1 2 +3 2 diff --git a/rede-anel-estelar/input/33 b/rede-anel-estelar/input/33 new file mode 100644 index 0000000..d094b48 --- /dev/null +++ b/rede-anel-estelar/input/33 @@ -0,0 +1,4 @@ +4 3 +1 2 +3 1 +1 4 diff --git a/rede-anel-estelar/input/34 b/rede-anel-estelar/input/34 new file mode 100644 index 0000000..0979a7e --- /dev/null +++ b/rede-anel-estelar/input/34 @@ -0,0 +1,8 @@ +8 7 +7 3 +7 2 +2 4 +2 8 +3 1 +6 1 +5 7 diff --git a/rede-anel-estelar/input/35 b/rede-anel-estelar/input/35 new file mode 100644 index 0000000..9ecb952 --- /dev/null +++ b/rede-anel-estelar/input/35 @@ -0,0 +1,14 @@ +8 13 +3 8 +5 1 +8 2 +8 6 +4 1 +1 2 +4 7 +4 5 +5 3 +4 6 +6 1 +8 4 +5 2 diff --git a/rede-anel-estelar/input/36 b/rede-anel-estelar/input/36 new file mode 100644 index 0000000..07fcc14 --- /dev/null +++ b/rede-anel-estelar/input/36 @@ -0,0 +1,9 @@ +8 8 +8 2 +3 2 +6 1 +4 5 +8 7 +6 5 +4 3 +1 7 diff --git a/rede-anel-estelar/input/37 b/rede-anel-estelar/input/37 new file mode 100644 index 0000000..0f8af46 --- /dev/null +++ b/rede-anel-estelar/input/37 @@ -0,0 +1,6 @@ +6 5 +6 1 +4 6 +5 6 +3 5 +2 5 diff --git a/rede-anel-estelar/input/38 b/rede-anel-estelar/input/38 new file mode 100644 index 0000000..bd43d32 --- /dev/null +++ b/rede-anel-estelar/input/38 @@ -0,0 +1,19 @@ +18 18 +15 18 +15 12 +8 15 +2 9 +16 17 +2 3 +1 11 +4 12 +18 16 +5 7 +16 9 +10 13 +10 1 +5 14 +14 2 +15 11 +5 11 +6 16 diff --git a/rede-anel-estelar/input/39 b/rede-anel-estelar/input/39 new file mode 100644 index 0000000..b43a62d --- /dev/null +++ b/rede-anel-estelar/input/39 @@ -0,0 +1,22 @@ +16 21 +16 4 +5 7 +11 9 +5 1 +9 3 +10 9 +4 13 +9 15 +11 2 +4 5 +8 1 +4 10 +11 6 +14 16 +12 7 +15 8 +2 1 +8 2 +6 9 +8 6 +4 15 diff --git a/rede-anel-estelar/input/4 b/rede-anel-estelar/input/4 new file mode 100644 index 0000000..fe1baf4 --- /dev/null +++ b/rede-anel-estelar/input/4 @@ -0,0 +1,3 @@ +3 2 +2 3 +1 2 diff --git a/rede-anel-estelar/input/40 b/rede-anel-estelar/input/40 new file mode 100644 index 0000000..586ce46 --- /dev/null +++ b/rede-anel-estelar/input/40 @@ -0,0 +1,12 @@ +11 11 +4 10 +5 4 +8 7 +2 7 +9 6 +7 10 +1 4 +9 11 +11 1 +3 4 +7 9 diff --git a/rede-anel-estelar/input/41 b/rede-anel-estelar/input/41 new file mode 100644 index 0000000..23317fc --- /dev/null +++ b/rede-anel-estelar/input/41 @@ -0,0 +1,29 @@ +28 28 +5 28 +21 3 +13 5 +7 12 +17 7 +26 25 +16 7 +12 1 +2 10 +12 22 +19 23 +6 24 +23 16 +16 15 +10 16 +23 27 +8 3 +4 14 +21 18 +19 4 +19 24 +1 6 +24 9 +23 21 +19 5 +25 21 +6 20 +11 22 diff --git a/rede-anel-estelar/input/42 b/rede-anel-estelar/input/42 new file mode 100644 index 0000000..0cb78df --- /dev/null +++ b/rede-anel-estelar/input/42 @@ -0,0 +1,33 @@ +27 32 +2 10 +16 11 +17 4 +8 6 +24 7 +19 8 +13 7 +18 21 +27 12 +19 4 +8 3 +25 8 +13 25 +10 19 +13 6 +1 8 +16 26 +13 9 +16 23 +3 6 +15 12 +19 3 +11 3 +2 18 +2 22 +23 3 +8 23 +18 5 +14 6 +25 3 +12 20 +27 4 diff --git a/rede-anel-estelar/input/43 b/rede-anel-estelar/input/43 new file mode 100644 index 0000000..3e7f21f --- /dev/null +++ b/rede-anel-estelar/input/43 @@ -0,0 +1,13 @@ +12 12 +8 11 +3 12 +5 10 +2 4 +2 10 +4 7 +1 9 +5 11 +2 6 +8 1 +5 3 +1 7 diff --git a/rede-anel-estelar/input/44 b/rede-anel-estelar/input/44 new file mode 100644 index 0000000..e0bbb4d --- /dev/null +++ b/rede-anel-estelar/input/44 @@ -0,0 +1,18 @@ +17 17 +7 13 +16 5 +9 8 +11 2 +3 17 +8 2 +4 5 +2 14 +2 17 +4 15 +6 16 +12 13 +7 10 +3 1 +9 6 +1 10 +13 15 diff --git a/rede-anel-estelar/input/45 b/rede-anel-estelar/input/45 new file mode 100644 index 0000000..f8ae108 --- /dev/null +++ b/rede-anel-estelar/input/45 @@ -0,0 +1,16 @@ +15 15 +9 1 +5 15 +9 10 +2 7 +13 11 +8 3 +4 5 +7 9 +1 12 +4 6 +11 3 +14 8 +13 15 +2 14 +6 12 diff --git a/rede-anel-estelar/input/46 b/rede-anel-estelar/input/46 new file mode 100644 index 0000000..1d4f041 --- /dev/null +++ b/rede-anel-estelar/input/46 @@ -0,0 +1,12 @@ +6 11 +4 6 +3 2 +6 5 +1 4 +3 4 +1 6 +3 6 +5 2 +3 1 +1 2 +6 2 diff --git a/rede-anel-estelar/input/47 b/rede-anel-estelar/input/47 new file mode 100644 index 0000000..8f3d7e4 --- /dev/null +++ b/rede-anel-estelar/input/47 @@ -0,0 +1,29 @@ +28 28 +23 9 +8 28 +13 25 +10 22 +8 11 +18 4 +12 10 +21 23 +3 8 +25 5 +15 13 +16 2 +17 7 +6 21 +25 20 +21 7 +9 13 +16 4 +12 19 +27 17 +26 11 +2 11 +14 15 +22 1 +4 5 +27 22 +16 24 +12 8 diff --git a/rede-anel-estelar/input/48 b/rede-anel-estelar/input/48 new file mode 100644 index 0000000..832e0a7 --- /dev/null +++ b/rede-anel-estelar/input/48 @@ -0,0 +1,23 @@ +22 22 +15 10 +7 21 +18 2 +17 8 +3 4 +13 20 +4 20 +19 6 +18 14 +6 21 +15 22 +16 15 +5 19 +11 1 +12 1 +5 14 +8 13 +12 2 +2 9 +11 10 +22 17 +7 3 diff --git a/rede-anel-estelar/input/49 b/rede-anel-estelar/input/49 new file mode 100644 index 0000000..1181bc4 --- /dev/null +++ b/rede-anel-estelar/input/49 @@ -0,0 +1,25 @@ +24 24 +6 4 +24 17 +18 11 +23 3 +6 14 +12 24 +11 19 +1 9 +22 9 +6 22 +13 21 +16 17 +19 15 +11 6 +20 18 +14 5 +5 2 +21 6 +14 3 +7 3 +24 6 +18 21 +22 8 +9 10 diff --git a/rede-anel-estelar/input/5 b/rede-anel-estelar/input/5 new file mode 100644 index 0000000..b5c1c7b --- /dev/null +++ b/rede-anel-estelar/input/5 @@ -0,0 +1,4 @@ +4 3 +1 2 +1 4 +3 1 diff --git a/rede-anel-estelar/input/50 b/rede-anel-estelar/input/50 new file mode 100644 index 0000000..14b17b6 --- /dev/null +++ b/rede-anel-estelar/input/50 @@ -0,0 +1,28 @@ +27 27 +13 20 +24 25 +13 18 +10 5 +18 22 +11 21 +3 21 +1 17 +2 15 +19 7 +23 2 +9 23 +19 27 +14 26 +9 16 +14 11 +6 26 +8 11 +12 13 +16 4 +22 6 +7 15 +3 19 +21 5 +17 23 +15 24 +13 16 diff --git a/rede-anel-estelar/input/51 b/rede-anel-estelar/input/51 new file mode 100644 index 0000000..496f4b2 --- /dev/null +++ b/rede-anel-estelar/input/51 @@ -0,0 +1,23 @@ +22 22 +6 11 +8 18 +2 15 +17 9 +3 17 +14 12 +5 11 +20 1 +21 17 +7 15 +13 1 +8 6 +11 14 +9 20 +21 16 +4 17 +22 9 +19 18 +2 12 +10 7 +18 1 +10 3 diff --git a/rede-anel-estelar/input/52 b/rede-anel-estelar/input/52 new file mode 100644 index 0000000..afbb924 --- /dev/null +++ b/rede-anel-estelar/input/52 @@ -0,0 +1,7 @@ +7 6 +6 2 +3 4 +6 3 +6 1 +2 5 +7 3 diff --git a/rede-anel-estelar/input/53 b/rede-anel-estelar/input/53 new file mode 100644 index 0000000..d6aa33a --- /dev/null +++ b/rede-anel-estelar/input/53 @@ -0,0 +1,17 @@ +16 16 +8 13 +11 4 +14 7 +3 4 +1 4 +9 13 +1 9 +4 12 +10 9 +6 2 +8 16 +4 2 +1 15 +16 12 +7 8 +5 4 diff --git a/rede-anel-estelar/input/54 b/rede-anel-estelar/input/54 new file mode 100644 index 0000000..23189a9 --- /dev/null +++ b/rede-anel-estelar/input/54 @@ -0,0 +1,14 @@ +8 13 +2 4 +6 1 +8 7 +4 1 +4 8 +6 2 +2 1 +7 1 +5 4 +5 3 +5 6 +3 4 +8 1 diff --git a/rede-anel-estelar/input/55 b/rede-anel-estelar/input/55 new file mode 100644 index 0000000..39a2012 --- /dev/null +++ b/rede-anel-estelar/input/55 @@ -0,0 +1,94 @@ +93 93 +77 3 +44 7 +87 23 +18 45 +42 74 +21 53 +6 51 +86 13 +15 36 +75 45 +92 28 +10 44 +92 47 +11 61 +2 66 +26 82 +5 37 +5 44 +79 48 +59 62 +13 88 +17 5 +66 46 +11 43 +70 4 +91 78 +34 80 +67 27 +36 80 +11 72 +36 70 +16 1 +25 55 +76 56 +85 75 +32 47 +51 57 +29 72 +29 69 +41 2 +20 62 +48 41 +53 1 +62 30 +38 19 +50 54 +62 25 +35 74 +3 74 +91 34 +45 51 +4 77 +80 64 +68 23 +36 14 +92 13 +53 9 +54 5 +12 83 +38 71 +54 58 +84 58 +53 52 +66 38 +82 22 +69 89 +56 57 +11 33 +81 50 +46 31 +47 73 +89 41 +24 28 +60 53 +65 76 +33 39 +55 32 +93 53 +90 64 +9 81 +54 63 +28 40 +51 68 +68 8 +66 86 +27 2 +83 39 +22 54 +74 12 +20 58 +49 8 +60 85 +68 91 diff --git a/rede-anel-estelar/input/56 b/rede-anel-estelar/input/56 new file mode 100644 index 0000000..b12f4ea --- /dev/null +++ b/rede-anel-estelar/input/56 @@ -0,0 +1,49 @@ +43 48 +43 10 +9 15 +43 39 +31 19 +38 40 +34 29 +33 24 +42 21 +12 6 +42 39 +30 17 +28 39 +39 2 +24 39 +19 30 +3 42 +19 12 +14 8 +22 24 +25 39 +23 3 +19 1 +17 39 +24 34 +1 16 +9 27 +15 4 +28 37 +18 28 +3 29 +40 27 +11 17 +18 32 +5 38 +22 35 +17 20 +13 12 +7 26 +10 42 +3 14 +15 43 +40 28 +8 41 +27 30 +16 17 +26 25 +3 36 +19 37 diff --git a/rede-anel-estelar/input/57 b/rede-anel-estelar/input/57 new file mode 100644 index 0000000..3720b7b --- /dev/null +++ b/rede-anel-estelar/input/57 @@ -0,0 +1,66 @@ +65 65 +57 45 +36 5 +15 18 +2 38 +50 35 +13 29 +32 37 +61 59 +31 26 +4 1 +6 63 +52 11 +56 58 +27 48 +34 51 +38 34 +14 19 +39 37 +32 12 +31 19 +6 14 +64 53 +1 46 +7 16 +53 61 +42 59 +35 62 +50 40 +17 53 +2 18 +25 19 +4 33 +49 44 +58 30 +39 49 +44 22 +2 65 +30 23 +22 28 +35 43 +28 52 +20 8 +55 9 +3 41 +29 14 +64 4 +5 34 +31 55 +56 11 +47 8 +21 12 +62 13 +41 40 +21 27 +18 57 +16 48 +20 24 +55 23 +51 1 +60 23 +57 47 +42 16 +52 10 +50 54 +20 41 diff --git a/rede-anel-estelar/input/58 b/rede-anel-estelar/input/58 new file mode 100644 index 0000000..4a93adf --- /dev/null +++ b/rede-anel-estelar/input/58 @@ -0,0 +1,19 @@ +18 18 +1 13 +18 15 +9 13 +6 16 +11 13 +12 8 +3 6 +2 10 +5 17 +8 6 +4 8 +2 14 +9 16 +18 10 +15 12 +1 7 +5 8 +11 18 diff --git a/rede-anel-estelar/input/59 b/rede-anel-estelar/input/59 new file mode 100644 index 0000000..219dd41 --- /dev/null +++ b/rede-anel-estelar/input/59 @@ -0,0 +1,60 @@ +54 59 +33 28 +43 29 +31 19 +2 32 +43 2 +6 27 +38 37 +26 28 +15 3 +28 40 +27 25 +30 38 +40 53 +5 47 +13 50 +36 1 +14 16 +35 54 +15 35 +28 45 +37 29 +51 47 +12 17 +50 47 +21 10 +11 18 +41 32 +29 24 +29 48 +46 39 +42 12 +2 46 +29 19 +22 18 +14 22 +30 44 +25 46 +53 52 +18 5 +49 15 +36 15 +24 20 +43 12 +30 4 +22 15 +2 18 +2 21 +17 18 +41 17 +7 22 +46 8 +23 52 +9 53 +28 15 +34 11 +33 27 +23 41 +41 5 +50 18 diff --git a/rede-anel-estelar/input/6 b/rede-anel-estelar/input/6 new file mode 100644 index 0000000..87bf7a3 --- /dev/null +++ b/rede-anel-estelar/input/6 @@ -0,0 +1,8 @@ +8 7 +8 7 +7 5 +4 6 +2 8 +7 3 +1 2 +5 4 diff --git a/rede-anel-estelar/input/60 b/rede-anel-estelar/input/60 new file mode 100644 index 0000000..2237089 --- /dev/null +++ b/rede-anel-estelar/input/60 @@ -0,0 +1,33 @@ +32 32 +31 23 +13 10 +25 2 +13 14 +28 27 +20 29 +14 6 +4 32 +16 5 +5 18 +1 6 +32 19 +29 13 +15 5 +25 11 +22 21 +32 7 +24 29 +23 17 +6 2 +26 30 +24 31 +22 5 +17 5 +29 12 +28 26 +8 32 +21 7 +3 4 +25 26 +4 27 +25 9 diff --git a/rede-anel-estelar/input/61 b/rede-anel-estelar/input/61 new file mode 100644 index 0000000..804ffa3 --- /dev/null +++ b/rede-anel-estelar/input/61 @@ -0,0 +1,13 @@ +12 12 +10 9 +3 4 +7 5 +6 1 +7 8 +2 9 +7 11 +12 4 +9 11 +4 7 +7 1 +7 10 diff --git a/rede-anel-estelar/input/62 b/rede-anel-estelar/input/62 new file mode 100644 index 0000000..d1ae1c6 --- /dev/null +++ b/rede-anel-estelar/input/62 @@ -0,0 +1,99 @@ +98 98 +67 27 +82 35 +96 30 +52 32 +88 20 +90 13 +80 17 +1 70 +97 79 +61 38 +7 15 +36 76 +54 19 +57 86 +81 77 +40 61 +60 89 +2 79 +50 65 +71 41 +65 10 +94 16 +26 91 +70 42 +66 27 +11 26 +15 5 +90 39 +68 82 +89 83 +30 68 +14 84 +75 35 +17 97 +94 33 +27 73 +50 22 +63 57 +12 10 +45 91 +14 20 +47 31 +69 91 +56 11 +12 64 +6 18 +30 16 +69 34 +54 18 +23 40 +75 8 +21 48 +37 87 +25 4 +41 86 +52 59 +9 60 +62 4 +33 78 +19 72 +33 25 +74 26 +93 6 +90 43 +75 55 +21 1 +46 95 +23 51 +49 56 +13 58 +66 92 +81 3 +36 39 +53 70 +29 77 +83 80 +3 98 +95 51 +9 67 +31 38 +47 42 +7 44 +85 84 +5 49 +85 72 +63 20 +44 21 +8 27 +29 2 +62 87 +76 32 +12 37 +77 28 +52 98 +24 83 +22 34 +93 58 +95 41 diff --git a/rede-anel-estelar/input/63 b/rede-anel-estelar/input/63 new file mode 100644 index 0000000..dfa6961 --- /dev/null +++ b/rede-anel-estelar/input/63 @@ -0,0 +1,84 @@ +83 83 +66 42 +51 66 +4 16 +45 78 +4 75 +63 28 +69 8 +69 37 +41 74 +54 30 +27 80 +71 32 +2 37 +36 31 +23 48 +83 65 +21 18 +43 74 +14 2 +35 36 +75 17 +18 44 +21 12 +82 19 +23 32 +3 41 +13 6 +49 77 +68 54 +33 5 +65 58 +47 46 +16 76 +70 83 +27 61 +14 3 +76 40 +53 73 +79 25 +29 22 +78 55 +33 30 +42 56 +59 52 +80 38 +12 20 +58 9 +61 63 +1 19 +62 6 +28 73 +62 67 +81 49 +50 70 +15 55 +10 38 +67 45 +72 57 +11 43 +43 64 +15 60 +81 47 +82 56 +5 46 +43 50 +34 11 +71 68 +57 29 +59 24 +76 48 +26 6 +7 74 +31 17 +10 72 +75 39 +35 58 +22 8 +51 77 +13 53 +20 24 +15 44 +40 25 +1 52 diff --git a/rede-anel-estelar/input/64 b/rede-anel-estelar/input/64 new file mode 100644 index 0000000..6e4cc25 --- /dev/null +++ b/rede-anel-estelar/input/64 @@ -0,0 +1,38 @@ +37 37 +24 20 +26 30 +1 13 +16 15 +21 6 +4 18 +8 31 +2 15 +20 27 +28 25 +23 32 +11 37 +12 13 +29 22 +21 26 +19 30 +23 35 +27 19 +33 11 +36 12 +34 19 +12 7 +36 32 +9 22 +3 2 +5 15 +36 14 +5 17 +17 35 +33 18 +22 3 +31 4 +9 25 +37 28 +6 8 +24 1 +10 21 diff --git a/rede-anel-estelar/input/65 b/rede-anel-estelar/input/65 new file mode 100644 index 0000000..1a19dba --- /dev/null +++ b/rede-anel-estelar/input/65 @@ -0,0 +1,82 @@ +81 81 +56 25 +37 13 +55 15 +5 33 +16 36 +39 74 +54 35 +72 65 +48 3 +59 79 +33 48 +75 4 +64 61 +26 28 +17 50 +47 50 +5 42 +42 77 +19 76 +32 41 +77 36 +69 23 +14 46 +21 62 +52 18 +29 58 +63 45 +70 80 +15 30 +66 45 +9 41 +65 73 +56 1 +53 12 +24 7 +9 57 +38 10 +31 8 +75 40 +32 34 +60 44 +51 21 +4 74 +3 71 +55 24 +46 70 +81 16 +35 62 +23 39 +68 67 +17 19 +79 44 +60 54 +73 1 +52 10 +38 63 +11 12 +22 71 +27 80 +2 72 +67 11 +47 28 +57 49 +29 59 +40 61 +25 27 +51 8 +66 68 +20 49 +78 6 +34 22 +20 78 +58 18 +53 13 +69 6 +2 43 +43 37 +64 30 +76 81 +26 7 +14 31 diff --git a/rede-anel-estelar/input/66 b/rede-anel-estelar/input/66 new file mode 100644 index 0000000..697ecf0 --- /dev/null +++ b/rede-anel-estelar/input/66 @@ -0,0 +1,25 @@ +24 24 +4 20 +22 24 +23 11 +14 11 +7 20 +20 6 +20 9 +15 19 +15 24 +22 11 +21 10 +21 14 +1 9 +6 21 +16 1 +3 20 +19 8 +17 20 +5 7 +8 17 +19 12 +18 17 +13 21 +2 23 diff --git a/rede-anel-estelar/input/67 b/rede-anel-estelar/input/67 new file mode 100644 index 0000000..7198488 --- /dev/null +++ b/rede-anel-estelar/input/67 @@ -0,0 +1,71 @@ +70 70 +33 11 +37 11 +49 33 +66 1 +53 10 +70 48 +54 44 +18 2 +5 45 +61 17 +63 2 +49 6 +10 4 +69 47 +65 19 +27 36 +14 68 +62 55 +41 7 +26 28 +15 25 +69 60 +38 17 +25 38 +20 6 +52 40 +15 21 +48 46 +41 57 +67 22 +54 47 +30 50 +3 5 +27 7 +60 53 +14 44 +19 56 +26 24 +8 57 +65 31 +29 42 +21 45 +30 35 +68 67 +43 12 +62 63 +34 9 +4 32 +70 52 +13 39 +12 42 +58 51 +8 34 +16 56 +24 61 +64 9 +40 55 +36 59 +23 28 +66 39 +58 59 +16 32 +18 22 +64 13 +1 20 +51 3 +29 46 +43 35 +23 37 +31 50 diff --git a/rede-anel-estelar/input/68 b/rede-anel-estelar/input/68 new file mode 100644 index 0000000..dbd2572 --- /dev/null +++ b/rede-anel-estelar/input/68 @@ -0,0 +1,72 @@ +71 71 +3 7 +11 47 +55 26 +71 1 +22 31 +39 15 +59 21 +8 19 +3 63 +41 2 +18 22 +9 62 +48 29 +39 56 +69 19 +38 68 +43 51 +64 14 +67 34 +22 14 +37 29 +46 30 +50 40 +60 16 +35 66 +6 36 +3 36 +2 59 +38 40 +30 49 +32 57 +42 13 +9 64 +67 45 +68 8 +9 53 +57 27 +22 65 +7 1 +28 10 +4 51 +12 25 +15 54 +58 52 +69 24 +35 41 +69 60 +46 13 +23 56 +49 18 +45 5 +20 32 +21 10 +52 55 +50 45 +67 48 +61 3 +12 11 +33 31 +70 44 +32 44 +25 71 +32 24 +48 17 +43 37 +47 42 +6 58 +28 54 +62 23 +27 52 +66 4 diff --git a/rede-anel-estelar/input/69 b/rede-anel-estelar/input/69 new file mode 100644 index 0000000..7ad9f1d --- /dev/null +++ b/rede-anel-estelar/input/69 @@ -0,0 +1,51 @@ +50 50 +47 12 +39 36 +24 37 +37 41 +34 15 +12 5 +50 7 +7 17 +28 4 +20 18 +45 14 +22 2 +33 48 +8 34 +17 32 +38 11 +50 9 +48 18 +47 23 +45 30 +40 42 +46 14 +16 43 +18 44 +1 43 +24 49 +9 21 +3 47 +31 12 +10 44 +49 25 +38 3 +35 46 +21 28 +41 6 +8 25 +42 27 +22 35 +28 16 +2 27 +6 36 +5 1 +10 29 +13 26 +33 26 +29 11 +40 17 +19 5 +13 39 +14 15 diff --git a/rede-anel-estelar/input/7 b/rede-anel-estelar/input/7 new file mode 100644 index 0000000..2436a73 --- /dev/null +++ b/rede-anel-estelar/input/7 @@ -0,0 +1,8 @@ +7 7 +3 7 +1 3 +2 4 +7 6 +6 1 +2 5 +5 4 diff --git a/rede-anel-estelar/input/70 b/rede-anel-estelar/input/70 new file mode 100644 index 0000000..120fc28 --- /dev/null +++ b/rede-anel-estelar/input/70 @@ -0,0 +1,57 @@ +56 56 +23 28 +31 24 +49 23 +45 56 +36 24 +19 21 +45 9 +51 26 +55 46 +16 14 +17 1 +1 55 +11 47 +35 11 +6 50 +54 44 +42 50 +4 9 +34 53 +24 40 +51 13 +25 48 +17 33 +18 27 +19 40 +5 14 +5 20 +45 43 +53 20 +38 41 +48 26 +11 43 +8 41 +10 3 +30 54 +3 53 +15 44 +17 48 +26 41 +39 24 +27 21 +31 54 +16 7 +10 38 +52 32 +6 7 +11 6 +32 26 +51 29 +18 12 +39 55 +27 9 +23 45 +37 7 +31 2 +24 22 diff --git a/rede-anel-estelar/input/71 b/rede-anel-estelar/input/71 new file mode 100644 index 0000000..45a0f59 --- /dev/null +++ b/rede-anel-estelar/input/71 @@ -0,0 +1,55 @@ +55 54 +47 16 +52 55 +39 8 +1 48 +7 9 +13 14 +24 55 +27 35 +8 23 +9 4 +8 19 +21 16 +46 54 +35 6 +48 38 +33 35 +48 55 +53 35 +36 12 +2 3 +22 43 +51 1 +53 50 +6 34 +15 6 +8 3 +9 45 +18 1 +44 55 +6 30 +55 53 +11 8 +46 13 +46 35 +42 50 +54 32 +44 10 +31 3 +37 53 +45 29 +53 40 +17 41 +16 18 +23 35 +13 5 +24 20 +53 12 +49 28 +46 28 +6 43 +26 1 +41 40 +18 25 +44 9 diff --git a/rede-anel-estelar/input/72 b/rede-anel-estelar/input/72 new file mode 100644 index 0000000..6855d3c --- /dev/null +++ b/rede-anel-estelar/input/72 @@ -0,0 +1,32 @@ +31 31 +29 15 +30 10 +30 8 +14 5 +27 17 +10 9 +3 13 +28 17 +28 24 +21 4 +31 1 +25 4 +26 12 +22 18 +26 16 +19 30 +9 1 +7 20 +27 15 +8 6 +22 13 +18 2 +7 5 +16 3 +20 11 +23 11 +29 2 +12 14 +21 23 +25 31 +6 28 diff --git a/rede-anel-estelar/input/73 b/rede-anel-estelar/input/73 new file mode 100644 index 0000000..c863144 --- /dev/null +++ b/rede-anel-estelar/input/73 @@ -0,0 +1,17 @@ +16 16 +8 10 +6 3 +1 11 +2 16 +2 1 +6 15 +16 5 +12 14 +15 9 +9 4 +7 10 +5 6 +16 13 +1 7 +12 8 +14 4 diff --git a/rede-anel-estelar/input/74 b/rede-anel-estelar/input/74 new file mode 100644 index 0000000..0ccaf04 --- /dev/null +++ b/rede-anel-estelar/input/74 @@ -0,0 +1,21 @@ +20 20 +19 2 +11 13 +18 13 +15 20 +8 2 +11 9 +3 16 +1 13 +12 5 +17 20 +9 5 +4 11 +15 11 +3 6 +3 19 +5 3 +19 1 +14 10 +14 15 +7 13 diff --git a/rede-anel-estelar/input/75 b/rede-anel-estelar/input/75 new file mode 100644 index 0000000..e35d76f --- /dev/null +++ b/rede-anel-estelar/input/75 @@ -0,0 +1,92 @@ +91 91 +6 1 +90 35 +26 36 +80 73 +33 88 +55 63 +64 33 +14 29 +22 66 +54 53 +38 89 +42 12 +80 66 +51 8 +1 38 +37 30 +15 16 +5 77 +56 36 +35 32 +6 11 +58 32 +66 64 +57 39 +15 4 +75 77 +37 64 +23 78 +7 12 +69 87 +66 61 +45 62 +45 38 +51 1 +46 8 +14 76 +9 33 +31 87 +89 52 +40 19 +18 80 +21 71 +71 85 +80 13 +38 71 +14 50 +66 44 +10 32 +49 16 +12 29 +38 87 +23 73 +80 15 +48 71 +64 54 +38 82 +87 47 +28 12 +22 55 +60 5 +17 56 +39 22 +59 70 +60 86 +84 91 +70 11 +76 41 +72 82 +90 3 +25 22 +12 73 +61 24 +57 74 +43 70 +2 87 +1 35 +20 21 +40 11 +11 77 +22 56 +29 83 +12 34 +79 43 +62 66 +15 27 +4 67 +89 65 +69 81 +84 1 +71 29 +68 80 diff --git a/rede-anel-estelar/input/76 b/rede-anel-estelar/input/76 new file mode 100644 index 0000000..dc13e47 --- /dev/null +++ b/rede-anel-estelar/input/76 @@ -0,0 +1,88 @@ +87 87 +5 45 +41 46 +13 36 +3 16 +56 49 +82 58 +83 4 +61 23 +44 83 +23 55 +21 60 +16 28 +6 49 +71 39 +81 74 +31 55 +7 22 +46 76 +24 33 +75 7 +1 45 +75 8 +17 30 +74 82 +71 50 +2 87 +18 73 +67 29 +13 86 +25 69 +62 20 +59 52 +66 7 +53 26 +32 69 +73 13 +9 75 +39 14 +47 71 +72 22 +38 34 +36 42 +32 18 +57 29 +79 80 +3 47 +71 51 +54 77 +85 5 +29 48 +85 33 +11 50 +61 33 +49 60 +54 37 +62 36 +17 67 +13 10 +46 87 +80 67 +19 51 +26 29 +26 28 +69 52 +37 1 +39 46 +15 31 +84 28 +87 12 +13 40 +11 64 +27 34 +6 55 +70 81 +75 40 +68 44 +47 35 +31 43 +77 58 +12 72 +3 63 +34 17 +70 27 +68 52 +78 50 +21 4 +65 24 diff --git a/rede-anel-estelar/input/77 b/rede-anel-estelar/input/77 new file mode 100644 index 0000000..1bc591c --- /dev/null +++ b/rede-anel-estelar/input/77 @@ -0,0 +1,76 @@ +75 75 +60 7 +13 67 +75 45 +36 47 +52 65 +11 54 +3 23 +22 38 +71 51 +60 27 +73 48 +5 36 +37 26 +48 20 +44 62 +39 19 +53 63 +50 35 +73 45 +47 15 +14 62 +61 33 +47 30 +49 31 +32 8 +42 18 +51 29 +48 24 +18 12 +42 57 +50 67 +46 56 +40 4 +59 26 +21 69 +54 41 +34 63 +25 7 +68 2 +8 65 +17 38 +32 72 +56 33 +74 15 +31 21 +1 48 +68 72 +27 39 +20 64 +70 55 +53 10 +23 64 +12 9 +13 58 +3 57 +6 52 +29 40 +5 25 +14 9 +66 16 +17 74 +55 6 +44 70 +71 69 +34 11 +75 37 +41 16 +35 49 +46 66 +50 28 +19 58 +10 22 +59 4 +31 43 +2 61 diff --git a/rede-anel-estelar/input/78 b/rede-anel-estelar/input/78 new file mode 100644 index 0000000..8cd8da6 --- /dev/null +++ b/rede-anel-estelar/input/78 @@ -0,0 +1,92 @@ +91 91 +12 39 +46 73 +18 69 +83 32 +81 78 +13 41 +59 89 +15 59 +24 80 +50 77 +17 76 +48 27 +35 84 +9 57 +52 68 +2 87 +24 21 +64 57 +51 23 +70 55 +53 33 +47 79 +66 6 +20 59 +32 3 +11 78 +1 49 +31 91 +26 14 +58 7 +13 35 +42 79 +45 72 +10 77 +26 43 +72 22 +12 5 +10 20 +21 90 +4 51 +62 40 +28 38 +63 58 +61 64 +74 60 +8 44 +65 19 +15 49 +2 25 +41 29 +80 70 +14 27 +34 56 +7 85 +32 44 +33 90 +28 68 +23 11 +85 67 +16 66 +18 6 +75 60 +87 53 +22 76 +17 39 +62 54 +36 38 +43 25 +84 1 +5 40 +46 56 +4 30 +82 63 +61 88 +71 36 +74 37 +37 81 +88 48 +52 75 +42 82 +50 34 +86 73 +69 30 +47 19 +55 16 +31 86 +8 54 +67 83 +9 45 +65 41 +91 71 diff --git a/rede-anel-estelar/input/79 b/rede-anel-estelar/input/79 new file mode 100644 index 0000000..0558cf1 --- /dev/null +++ b/rede-anel-estelar/input/79 @@ -0,0 +1,27 @@ +26 26 +18 8 +17 8 +12 17 +12 23 +3 11 +26 6 +22 15 +24 9 +11 19 +1 10 +7 13 +7 22 +18 24 +9 5 +13 16 +16 25 +14 10 +9 3 +4 18 +20 1 +26 8 +12 21 +2 14 +15 20 +14 19 +23 25 diff --git a/rede-anel-estelar/input/8 b/rede-anel-estelar/input/8 new file mode 100644 index 0000000..cd37e7a --- /dev/null +++ b/rede-anel-estelar/input/8 @@ -0,0 +1,5 @@ +4 4 +4 2 +2 3 +4 1 +1 2 diff --git a/rede-anel-estelar/input/80 b/rede-anel-estelar/input/80 new file mode 100644 index 0000000..6f6d066 --- /dev/null +++ b/rede-anel-estelar/input/80 @@ -0,0 +1,70 @@ +69 69 +66 59 +15 32 +11 18 +44 67 +2 12 +33 48 +69 3 +65 7 +37 20 +31 30 +49 30 +38 4 +52 6 +40 30 +6 59 +11 38 +19 12 +11 62 +35 22 +57 4 +40 58 +60 23 +69 25 +16 36 +45 46 +41 46 +14 61 +17 6 +3 6 +3 24 +43 9 +43 32 +45 15 +25 34 +43 39 +48 20 +38 10 +54 1 +63 26 +7 42 +48 19 +47 56 +38 53 +50 54 +14 29 +67 2 +55 52 +5 54 +36 37 +8 1 +68 13 +11 28 +29 13 +14 41 +23 22 +60 34 +1 55 +12 64 +63 31 +65 41 +36 51 +30 68 +9 16 +67 5 +47 66 +57 35 +27 60 +62 40 +21 6 diff --git a/rede-anel-estelar/input/81 b/rede-anel-estelar/input/81 new file mode 100644 index 0000000..70cb56b --- /dev/null +++ b/rede-anel-estelar/input/81 @@ -0,0 +1,19 @@ +19 18 +5 15 +19 18 +2 3 +10 19 +7 4 +14 8 +15 11 +1 18 +11 9 +15 8 +4 5 +13 15 +5 2 +6 17 +16 2 +17 5 +18 12 +5 10 diff --git a/rede-anel-estelar/input/82 b/rede-anel-estelar/input/82 new file mode 100644 index 0000000..8ce582f --- /dev/null +++ b/rede-anel-estelar/input/82 @@ -0,0 +1,24 @@ +23 23 +12 8 +4 1 +9 8 +16 11 +13 14 +19 23 +1 3 +6 11 +6 14 +4 23 +12 5 +17 7 +23 10 +19 21 +18 7 +15 22 +18 15 +12 15 +2 16 +13 9 +1 11 +7 19 +20 23 diff --git a/rede-anel-estelar/input/83 b/rede-anel-estelar/input/83 new file mode 100644 index 0000000..5514bb9 --- /dev/null +++ b/rede-anel-estelar/input/83 @@ -0,0 +1,80 @@ +79 79 +6 58 +78 37 +66 14 +31 35 +68 15 +8 16 +43 39 +46 76 +40 64 +24 50 +62 27 +49 53 +52 58 +64 48 +71 37 +50 10 +35 57 +21 36 +29 54 +63 12 +73 59 +45 47 +75 9 +42 66 +55 45 +3 25 +68 71 +35 70 +72 36 +43 18 +10 44 +41 13 +28 4 +28 33 +46 12 +56 33 +52 59 +22 49 +36 56 +66 62 +70 55 +14 34 +78 20 +38 11 +24 65 +27 32 +23 8 +28 54 +77 33 +63 8 +7 5 +51 11 +19 15 +74 51 +25 60 +34 17 +30 22 +30 47 +3 6 +19 69 +17 29 +61 2 +69 7 +5 79 +2 79 +13 16 +20 40 +18 67 +9 21 +61 44 +41 53 +39 26 +27 74 +38 39 +76 73 +47 1 +75 65 +31 67 +48 60 diff --git a/rede-anel-estelar/input/84 b/rede-anel-estelar/input/84 new file mode 100644 index 0000000..16b6d78 --- /dev/null +++ b/rede-anel-estelar/input/84 @@ -0,0 +1,91 @@ +90 90 +65 7 +83 30 +34 89 +31 52 +90 26 +62 54 +29 77 +22 84 +25 15 +79 45 +5 55 +3 14 +4 58 +43 31 +10 27 +73 15 +64 59 +59 76 +81 10 +72 20 +14 54 +12 63 +38 21 +22 33 +69 67 +9 62 +47 69 +61 90 +78 44 +14 79 +26 18 +22 17 +24 17 +71 23 +64 72 +37 72 +85 49 +37 29 +71 30 +61 60 +75 35 +48 8 +3 13 +88 34 +56 47 +30 2 +46 77 +21 70 +15 33 +80 16 +74 28 +8 69 +68 87 +38 26 +65 24 +44 79 +45 51 +78 8 +82 58 +31 13 +60 82 +77 57 +34 65 +86 17 +88 1 +5 66 +40 67 +67 59 +11 27 +81 66 +66 19 +50 49 +36 32 +4 52 +15 16 +21 73 +1 41 +11 28 +88 42 +1 68 +39 84 +85 12 +50 68 +75 41 +53 85 +11 57 +36 55 +1 30 +6 44 +32 85 diff --git a/rede-anel-estelar/input/85 b/rede-anel-estelar/input/85 new file mode 100644 index 0000000..36fa72a --- /dev/null +++ b/rede-anel-estelar/input/85 @@ -0,0 +1,36 @@ +35 35 +29 3 +26 27 +9 34 +33 32 +16 2 +9 22 +5 8 +21 7 +1 8 +18 20 +12 8 +18 11 +24 10 +30 34 +4 17 +20 23 +6 23 +5 25 +19 17 +2 29 +3 25 +32 11 +14 27 +7 16 +6 22 +1 4 +28 33 +10 19 +15 24 +13 27 +33 10 +14 30 +35 21 +26 35 +23 31 diff --git a/rede-anel-estelar/input/86 b/rede-anel-estelar/input/86 new file mode 100644 index 0000000..2e5214d --- /dev/null +++ b/rede-anel-estelar/input/86 @@ -0,0 +1,4 @@ +3 3 +1 2 +1 3 +3 2 diff --git a/rede-anel-estelar/input/87 b/rede-anel-estelar/input/87 new file mode 100644 index 0000000..78ec31b --- /dev/null +++ b/rede-anel-estelar/input/87 @@ -0,0 +1,51 @@ +50 50 +34 24 +22 39 +14 30 +40 3 +29 19 +20 41 +42 11 +47 15 +36 24 +5 16 +9 1 +6 48 +15 21 +44 13 +41 30 +43 13 +38 43 +37 2 +16 46 +27 35 +24 17 +31 48 +49 40 +38 10 +42 28 +12 19 +18 45 +8 48 +46 32 +42 18 +17 14 +23 34 +37 47 +1 7 +5 41 +9 33 +7 4 +50 12 +10 27 +25 6 +23 25 +39 18 +11 33 +2 44 +50 22 +49 29 +26 3 +48 15 +4 35 +32 3 diff --git a/rede-anel-estelar/input/88 b/rede-anel-estelar/input/88 new file mode 100644 index 0000000..af5d824 --- /dev/null +++ b/rede-anel-estelar/input/88 @@ -0,0 +1,56 @@ +55 55 +44 27 +41 17 +52 18 +21 1 +35 27 +37 40 +37 48 +49 42 +36 30 +47 25 +7 23 +4 1 +51 14 +14 24 +19 55 +19 3 +47 9 +44 6 +7 18 +33 29 +48 43 +55 22 +39 23 +51 5 +5 13 +53 20 +43 31 +12 54 +30 16 +17 13 +45 20 +49 50 +8 3 +33 53 +11 32 +38 10 +38 32 +52 36 +4 41 +15 11 +40 26 +54 6 +34 29 +39 28 +8 42 +21 35 +24 2 +50 25 +9 12 +16 26 +45 46 +10 34 +22 2 +46 28 +31 15 diff --git a/rede-anel-estelar/input/89 b/rede-anel-estelar/input/89 new file mode 100644 index 0000000..da0e805 --- /dev/null +++ b/rede-anel-estelar/input/89 @@ -0,0 +1,30 @@ +29 29 +15 23 +4 9 +4 10 +29 4 +29 28 +8 2 +27 18 +22 25 +5 26 +11 2 +10 6 +3 24 +4 21 +5 28 +13 11 +28 1 +8 18 +20 8 +16 10 +9 14 +4 17 +24 2 +4 8 +19 6 +22 28 +15 28 +8 7 +12 2 +2 25 diff --git a/rede-anel-estelar/input/9 b/rede-anel-estelar/input/9 new file mode 100644 index 0000000..10a1540 --- /dev/null +++ b/rede-anel-estelar/input/9 @@ -0,0 +1,6 @@ +5 5 +1 4 +1 5 +2 3 +1 3 +3 5 diff --git a/rede-anel-estelar/input/90 b/rede-anel-estelar/input/90 new file mode 100644 index 0000000..fd359f7 --- /dev/null +++ b/rede-anel-estelar/input/90 @@ -0,0 +1,86 @@ +85 85 +77 23 +33 21 +80 18 +48 41 +56 24 +2 78 +35 61 +47 76 +79 40 +61 7 +72 47 +18 11 +54 69 +64 55 +41 43 +39 8 +58 17 +75 28 +39 26 +19 14 +21 81 +71 9 +37 38 +12 52 +51 13 +37 49 +13 15 +28 25 +53 34 +1 42 +32 65 +43 1 +7 11 +9 63 +17 56 +80 57 +25 55 +65 44 +31 49 +84 53 +42 74 +6 48 +45 38 +73 69 +67 46 +16 82 +19 36 +70 83 +27 58 +29 76 +15 73 +22 12 +44 60 +72 2 +60 23 +22 8 +27 74 +78 64 +4 68 +81 71 +26 14 +46 83 +70 20 +84 5 +35 51 +63 31 +3 54 +20 52 +85 40 +50 59 +62 3 +5 30 +57 24 +59 45 +36 33 +82 66 +32 16 +10 75 +50 29 +79 10 +68 30 +34 6 +62 66 +67 85 +77 4 diff --git a/rede-anel-estelar/input/91 b/rede-anel-estelar/input/91 new file mode 100644 index 0000000..e7468fb --- /dev/null +++ b/rede-anel-estelar/input/91 @@ -0,0 +1,71 @@ +71 70 +26 41 +1 33 +39 40 +32 35 +36 19 +63 52 +43 15 +42 3 +6 38 +19 47 +35 56 +61 70 +26 71 +7 29 +53 11 +26 46 +50 17 +34 67 +7 15 +61 17 +1 15 +9 10 +67 23 +67 15 +64 27 +54 15 +8 43 +10 69 +1 18 +13 11 +4 1 +66 26 +5 27 +45 37 +12 49 +35 16 +46 12 +43 10 +41 23 +44 51 +60 35 +17 23 +25 1 +55 52 +38 35 +10 28 +19 42 +20 9 +17 62 +67 68 +38 48 +44 23 +35 41 +19 21 +47 24 +35 31 +17 19 +57 61 +7 27 +26 55 +67 2 +24 65 +37 11 +30 37 +14 23 +40 23 +51 58 +22 67 +13 15 +59 35 diff --git a/rede-anel-estelar/input/92 b/rede-anel-estelar/input/92 new file mode 100644 index 0000000..b4fa865 --- /dev/null +++ b/rede-anel-estelar/input/92 @@ -0,0 +1,56 @@ +56 55 +27 17 +33 35 +17 33 +9 21 +8 19 +10 4 +31 18 +10 47 +10 20 +3 1 +19 10 +14 45 +4 28 +21 36 +43 9 +9 18 +4 3 +26 45 +53 28 +42 34 +54 23 +23 45 +29 34 +4 2 +3 42 +10 5 +4 22 +53 56 +33 44 +51 34 +52 36 +10 17 +3 23 +41 18 +53 7 +46 49 +50 3 +55 49 +13 37 +19 11 +19 39 +30 14 +13 42 +20 15 +31 24 +42 12 +15 6 +18 10 +42 16 +53 38 +25 39 +40 54 +56 32 +48 9 +33 49 diff --git a/rede-anel-estelar/input/93 b/rede-anel-estelar/input/93 new file mode 100644 index 0000000..50b4030 --- /dev/null +++ b/rede-anel-estelar/input/93 @@ -0,0 +1,101 @@ +95 100 +61 56 +67 60 +72 43 +6 79 +8 91 +57 60 +7 70 +21 61 +27 75 +69 86 +41 33 +40 5 +3 95 +18 95 +28 18 +46 75 +71 80 +32 44 +45 11 +69 71 +22 40 +67 56 +30 20 +27 29 +43 24 +51 12 +6 52 +4 11 +37 92 +33 14 +80 66 +70 35 +29 17 +89 26 +80 9 +87 88 +16 26 +66 42 +3 27 +69 89 +44 36 +62 20 +33 31 +66 48 +17 39 +67 37 +23 27 +43 89 +15 90 +43 53 +52 40 +73 65 +68 50 +85 60 +54 3 +85 36 +23 93 +81 62 +55 43 +50 41 +4 19 +64 95 +59 34 +80 76 +13 37 +82 1 +19 89 +22 19 +41 78 +15 83 +94 44 +6 41 +36 84 +19 23 +58 86 +93 10 +87 93 +35 77 +35 95 +73 18 +44 80 +67 76 +63 5 +44 91 +69 33 +52 8 +76 1 +41 11 +25 71 +34 80 +74 91 +76 38 +19 90 +37 47 +20 49 +71 20 +45 34 +2 22 +43 51 +33 27 diff --git a/rede-anel-estelar/input/94 b/rede-anel-estelar/input/94 new file mode 100644 index 0000000..2491a74 --- /dev/null +++ b/rede-anel-estelar/input/94 @@ -0,0 +1,52 @@ +51 51 +14 30 +42 29 +33 31 +42 2 +24 32 +28 40 +8 25 +23 44 +17 49 +22 50 +38 24 +27 40 +19 23 +22 4 +40 34 +33 10 +32 46 +39 16 +17 30 +45 39 +4 42 +46 5 +45 21 +8 20 +16 7 +36 29 +36 18 +26 27 +14 12 +11 4 +31 17 +41 17 +33 3 +9 23 +22 9 +51 39 +40 47 +23 25 +43 40 +12 40 +31 13 +17 37 +18 47 +51 8 +12 6 +35 14 +32 34 +33 16 +11 1 +48 29 +15 41 diff --git a/rede-anel-estelar/input/95 b/rede-anel-estelar/input/95 new file mode 100644 index 0000000..2a9538e --- /dev/null +++ b/rede-anel-estelar/input/95 @@ -0,0 +1,29 @@ +28 28 +4 26 +6 1 +17 9 +19 4 +14 11 +3 5 +19 24 +14 12 +6 27 +5 16 +17 22 +13 8 +21 1 +11 3 +23 2 +23 15 +7 12 +28 15 +26 18 +9 25 +22 28 +2 13 +10 18 +20 24 +10 7 +16 20 +8 21 +25 27 diff --git a/rede-anel-estelar/input/96 b/rede-anel-estelar/input/96 new file mode 100644 index 0000000..57a1fd1 --- /dev/null +++ b/rede-anel-estelar/input/96 @@ -0,0 +1,60 @@ +59 59 +4 5 +54 30 +31 58 +35 2 +9 46 +52 51 +16 56 +57 53 +23 45 +12 37 +39 19 +26 25 +50 2 +3 6 +47 34 +22 4 +3 54 +31 27 +24 32 +31 53 +15 36 +9 40 +54 46 +8 43 +19 21 +12 17 +1 29 +27 42 +52 49 +29 25 +51 23 +28 19 +45 14 +9 36 +39 56 +26 5 +42 16 +13 18 +49 47 +38 14 +10 13 +41 1 +37 59 +37 53 +21 2 +7 41 +3 48 +34 11 +8 49 +19 44 +35 20 +13 33 +38 10 +11 32 +40 20 +6 22 +55 4 +17 13 +41 32 diff --git a/rede-anel-estelar/input/97 b/rede-anel-estelar/input/97 new file mode 100644 index 0000000..73e9440 --- /dev/null +++ b/rede-anel-estelar/input/97 @@ -0,0 +1,37 @@ +36 36 +9 21 +14 6 +6 12 +14 5 +31 21 +17 13 +20 33 +32 2 +22 4 +5 15 +10 15 +25 13 +7 19 +25 8 +4 34 +5 29 +23 8 +26 11 +17 3 +18 17 +31 28 +14 23 +35 16 +24 3 +2 19 +16 25 +30 3 +15 1 +33 2 +28 22 +21 26 +27 15 +34 33 +21 36 +18 19 +21 1 diff --git a/rede-anel-estelar/input/98 b/rede-anel-estelar/input/98 new file mode 100644 index 0000000..3121348 --- /dev/null +++ b/rede-anel-estelar/input/98 @@ -0,0 +1,63 @@ +62 62 +45 59 +40 31 +14 9 +51 16 +29 60 +35 11 +23 27 +59 62 +1 3 +3 16 +22 39 +18 30 +20 35 +34 12 +61 10 +51 49 +8 55 +10 12 +9 54 +54 15 +8 37 +43 25 +20 34 +32 24 +4 62 +21 25 +7 47 +53 29 +19 5 +55 6 +50 58 +5 17 +47 52 +13 60 +38 42 +22 46 +57 18 +39 61 +42 28 +28 40 +32 26 +11 37 +48 44 +33 57 +23 24 +19 53 +17 4 +56 15 +26 41 +56 38 +30 1 +43 36 +44 31 +46 7 +52 36 +33 2 +2 21 +13 41 +6 49 +27 48 +14 50 +58 45 diff --git a/rede-anel-estelar/input/99 b/rede-anel-estelar/input/99 new file mode 100644 index 0000000..a68d4c9 --- /dev/null +++ b/rede-anel-estelar/input/99 @@ -0,0 +1,11 @@ +11 10 +9 1 +10 11 +3 1 +8 6 +10 7 +6 3 +2 9 +5 4 +3 5 +6 11 diff --git a/rede-anel-estelar/maratona.cls b/rede-anel-estelar/maratona.cls new file mode 100644 index 0000000..e11d53d --- /dev/null +++ b/rede-anel-estelar/maratona.cls @@ -0,0 +1,188 @@ +\ProvidesPackage{maratona} +\LoadClass[11pt]{article} + +% remove page numbers +\pagenumbering{gobble} + +\RequirePackage{fancyhdr} + +\RequirePackage{tabularx,colortbl} + +%\RequirePackage{arial} +\RequirePackage{ifpdf} +\RequirePackage[T1]{fontenc} +\RequirePackage[utf8]{inputenc} +\RequirePackage[portuguese]{babel} +\RequirePackage{graphics} +\RequirePackage{graphicx} +\RequirePackage{amssymb,amsmath,wrapfig} +\RequirePackage{xcolor,colortbl} +\RequirePackage{xcolor} +\RequirePackage{ifthen} +\oddsidemargin 0cm +\evensidemargin -2cm +\topmargin -1cm +\textwidth 16cm +\textheight 23cm + +\ifpdf +\RequirePackage[pdftex]{hyperref} +\else +\RequirePackage[hypertex]{hyperref} +\fi + + +\newcommand{\var}[1]{\ensuremath{{#1}}} + + +\hypersetup{ + letterpaper, + colorlinks=true, + linkcolor=blue, + urlcolor=blue, + pdfpagemode=none, + pdftitle={IV Maratona de Programação do IFB \today}, + pdfauthor={}, + pdfsubject={Caderno de problemas da IV Maratona de Programação do IFB }, + pdfkeywords={maratona, programação, IFB} +} + + + +\DeclareGraphicsExtensions{png} + +\lhead{DS Contest Tools} +\pagestyle{fancy} + +% Capa +\newenvironment{Maratona}[3] +{ + \begin{titlepage} + \begin{center} + + \vspace{1cm} + \Large{\textbf{#1}} \\ + \vspace{1cm} + {\textbf{Caderno de Problemas}} \\ + \vspace{1cm} + \begin{small} + \textsl{#2} + \end{small} \\ + \begin{figure}[htp] + \begin{center} + \includegraphics[scale=1]{logos/logo-maratona.png} + \end{center} + \end{figure} + {(Este caderno contém {#3} problemas)} \\ + \vspace{1cm} + } + { + \vfill + \begin{small} + {QNM 40, Área Especial nº 01, + Taguatinga/DF, 72146-000 , + Brasil } \\ + {Telefone (61) 2103-2200 \\http://www.ifb.edu.br/taguatinga} \\ + \end{small} + \end{center} + \end{titlepage} +} + +\newcommand{\Organizacao}[2]{ + {\small \vfill + \begin{center} + + \textbf{Comissão Organizadora:} \\ + {#1} \\ + \bigskip + \textbf{Apoio:}\\ + {#2} + \end{center} + } + \vfill +} + + +% Problema +\newcounter{problem} +\newenvironment{Problema}[4]{ + \stepcounter{problem} + \newpage + \begin{center} + \Large{\ifthenelse{\equal{#1}{}}{\textbf{{#2}}}{\textbf{Problema {#1} -- {#2} }}}{\\\footnotesize \textbf{Limite de tempo: {#3}s}}{\\[-0.1cm]\footnotesize \textbf{Limite de memória: {#4}MB}} + \end{center} +} + +\newcounter{problemAutor} +\newenvironment{ProblemaAutor}[5]{ + \stepcounter{problemAutor} + \newpage + \begin{center} + \Large{\ifthenelse{\equal{#1}{}}{\textbf{{#2}}}{\textbf{Problema {#1} -- {#2} }}}{\\\footnotesize \textbf{Limite de tempo: {#3}s}}{\\[-0.1cm]\footnotesize \textbf{Limite de memória: {#4}MB\\}}{ + \footnotesize Autor: {#5} + } + \end{center} +} + + +% Código-fonte +\newcommand{\codigofonte}[1]{Nome do arquivo fonte: {#1}} + +% Entrada +\newcommand{\Entrada}{ + \bigskip + \begin{large} + \textbf{Entrada} \\ + \end{large} +} + +% Saida +\newcommand{\Saida}{ + \bigskip + \begin{large} + \textbf{Saída} \\ + \end{large} +} + +\newcommand{\Interacao}{ + \bigskip + \begin{large} + \textbf{Interação} \\ + \end{large} +} + +\newcommand{\Notas}{ + \bigskip + \begin{large} + \textbf{Notas} \\ + \end{large} +} + +% Exemplo +\newenvironment{Exemplo} +{ + + \tabularx{\textwidth}{XX} + % {@{\extracolsep{\fill}}|l|l|} + % {|l|l@{\extracolsep{\fill}|}} + \hline + Entrada & Saída \\\hline +} +{ + \hline + \endtabularx +} + +% Exemplo de Entrada +\newenvironment{ExemploEntrada} +{ + \bigskip + \begin{large} + \textbf{Exemplo} \\ + \end{large} +} +{ +} + +% Sample Output + diff --git a/rede-anel-estelar/output/1 b/rede-anel-estelar/output/1 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/1 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/10 b/rede-anel-estelar/output/10 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/10 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/100 b/rede-anel-estelar/output/100 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/100 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/101 b/rede-anel-estelar/output/101 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/101 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/102 b/rede-anel-estelar/output/102 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/102 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/103 b/rede-anel-estelar/output/103 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/103 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/104 b/rede-anel-estelar/output/104 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/104 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/105 b/rede-anel-estelar/output/105 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/105 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/11 b/rede-anel-estelar/output/11 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/11 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/12 b/rede-anel-estelar/output/12 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/12 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/13 b/rede-anel-estelar/output/13 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/13 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/14 b/rede-anel-estelar/output/14 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/14 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/15 b/rede-anel-estelar/output/15 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/15 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/16 b/rede-anel-estelar/output/16 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/16 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/17 b/rede-anel-estelar/output/17 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/17 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/18 b/rede-anel-estelar/output/18 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/18 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/19 b/rede-anel-estelar/output/19 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/19 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/2 b/rede-anel-estelar/output/2 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/2 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/20 b/rede-anel-estelar/output/20 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/20 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/21 b/rede-anel-estelar/output/21 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/21 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/22 b/rede-anel-estelar/output/22 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/22 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/23 b/rede-anel-estelar/output/23 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/23 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/24 b/rede-anel-estelar/output/24 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/24 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/25 b/rede-anel-estelar/output/25 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/25 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/26 b/rede-anel-estelar/output/26 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/26 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/27 b/rede-anel-estelar/output/27 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/27 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/28 b/rede-anel-estelar/output/28 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/28 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/29 b/rede-anel-estelar/output/29 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/29 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/3 b/rede-anel-estelar/output/3 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/3 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/30 b/rede-anel-estelar/output/30 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/30 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/31 b/rede-anel-estelar/output/31 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/31 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/32 b/rede-anel-estelar/output/32 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/32 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/33 b/rede-anel-estelar/output/33 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/33 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/34 b/rede-anel-estelar/output/34 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/34 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/35 b/rede-anel-estelar/output/35 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/35 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/36 b/rede-anel-estelar/output/36 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/36 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/37 b/rede-anel-estelar/output/37 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/37 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/38 b/rede-anel-estelar/output/38 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/38 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/39 b/rede-anel-estelar/output/39 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/39 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/4 b/rede-anel-estelar/output/4 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/4 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/40 b/rede-anel-estelar/output/40 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/40 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/41 b/rede-anel-estelar/output/41 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/41 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/42 b/rede-anel-estelar/output/42 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/42 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/43 b/rede-anel-estelar/output/43 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/43 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/44 b/rede-anel-estelar/output/44 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/44 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/45 b/rede-anel-estelar/output/45 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/45 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/46 b/rede-anel-estelar/output/46 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/46 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/47 b/rede-anel-estelar/output/47 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/47 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/48 b/rede-anel-estelar/output/48 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/48 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/49 b/rede-anel-estelar/output/49 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/49 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/5 b/rede-anel-estelar/output/5 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/5 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/50 b/rede-anel-estelar/output/50 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/50 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/51 b/rede-anel-estelar/output/51 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/51 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/52 b/rede-anel-estelar/output/52 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/52 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/53 b/rede-anel-estelar/output/53 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/53 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/54 b/rede-anel-estelar/output/54 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/54 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/55 b/rede-anel-estelar/output/55 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/55 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/56 b/rede-anel-estelar/output/56 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/56 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/57 b/rede-anel-estelar/output/57 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/57 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/58 b/rede-anel-estelar/output/58 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/58 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/59 b/rede-anel-estelar/output/59 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/59 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/6 b/rede-anel-estelar/output/6 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/6 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/60 b/rede-anel-estelar/output/60 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/60 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/61 b/rede-anel-estelar/output/61 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/61 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/62 b/rede-anel-estelar/output/62 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/62 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/63 b/rede-anel-estelar/output/63 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/63 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/64 b/rede-anel-estelar/output/64 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/64 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/65 b/rede-anel-estelar/output/65 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/65 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/66 b/rede-anel-estelar/output/66 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/66 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/67 b/rede-anel-estelar/output/67 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/67 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/68 b/rede-anel-estelar/output/68 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/68 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/69 b/rede-anel-estelar/output/69 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/69 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/7 b/rede-anel-estelar/output/7 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/7 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/70 b/rede-anel-estelar/output/70 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/70 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/71 b/rede-anel-estelar/output/71 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/71 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/72 b/rede-anel-estelar/output/72 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/72 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/73 b/rede-anel-estelar/output/73 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/73 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/74 b/rede-anel-estelar/output/74 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/74 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/75 b/rede-anel-estelar/output/75 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/75 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/76 b/rede-anel-estelar/output/76 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/76 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/77 b/rede-anel-estelar/output/77 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/77 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/78 b/rede-anel-estelar/output/78 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/78 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/79 b/rede-anel-estelar/output/79 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/79 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/8 b/rede-anel-estelar/output/8 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/8 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/80 b/rede-anel-estelar/output/80 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/80 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/81 b/rede-anel-estelar/output/81 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/81 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/82 b/rede-anel-estelar/output/82 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/82 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/83 b/rede-anel-estelar/output/83 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/83 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/84 b/rede-anel-estelar/output/84 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/84 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/85 b/rede-anel-estelar/output/85 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/85 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/86 b/rede-anel-estelar/output/86 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/86 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/87 b/rede-anel-estelar/output/87 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/87 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/88 b/rede-anel-estelar/output/88 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/88 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/89 b/rede-anel-estelar/output/89 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/89 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/9 b/rede-anel-estelar/output/9 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/9 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/90 b/rede-anel-estelar/output/90 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/90 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/91 b/rede-anel-estelar/output/91 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/91 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/92 b/rede-anel-estelar/output/92 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/92 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/93 b/rede-anel-estelar/output/93 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/93 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/94 b/rede-anel-estelar/output/94 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/94 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/95 b/rede-anel-estelar/output/95 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/95 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/96 b/rede-anel-estelar/output/96 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/96 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/97 b/rede-anel-estelar/output/97 new file mode 100644 index 0000000..1424865 --- /dev/null +++ b/rede-anel-estelar/output/97 @@ -0,0 +1 @@ +ONLINE diff --git a/rede-anel-estelar/output/98 b/rede-anel-estelar/output/98 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/98 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/output/99 b/rede-anel-estelar/output/99 new file mode 100644 index 0000000..ba32cbe --- /dev/null +++ b/rede-anel-estelar/output/99 @@ -0,0 +1 @@ +OFFLINE diff --git a/rede-anel-estelar/problem.json b/rede-anel-estelar/problem.json new file mode 100644 index 0000000..1469ebe --- /dev/null +++ b/rede-anel-estelar/problem.json @@ -0,0 +1,64 @@ +{ + "version": "1.0", + "problem": { + "title": "Rede Anel Estelar", + "event": "", + "time_limit": 1.0, + "memory_limit_mb": 256, + "input_file": "stdin", + "output_file": "stdout", + "interactive": false, + "grader": false, + "subject": { + "en_us": [ + "graph", "dfs", "bfs", "topological-sort" + ], + "pt_br": [ + "grafo", "busca-em-largura", "busca-em-profundidade", "ordenação-topológica" + ], + "es": [ + "" + ] + } + }, + "author": { + "name": "Arthur Andrade Dolival", + "affiliation": "", + "country": "", + "email": "" + }, + "build": { + "run_generator": true, + "run_validator": true, + "produce_outputs": true, + "run_checker": true, + "run_all_solutions": true, + "run_specific_solution": "", + "generate_io_only": false, + "generate_pdf_only": false, + "cpu_count": 1, + "build_pdf": true, + "pdf_format": "ds", + "io_samples": 3 + }, + "solutions": { + "main-ac": "ac.cpp", + "alternative-ac": ["alternative-ac.py"], + "wrong-answer": [], + "time-limit": [], + "time-limit-or-ac": [], + "time-limit-or-memory-limit": [], + "memory-limit": [], + "presentation-error": [], + "runtime-error": [] + }, + "polygon_config": { + "id": "" + }, + "boca_config": { + "time_limit": 1, + "number_of_repetitions": 1, + "maximum_memory_mb": 512, + "maximum_output_size_kb": 24096 + } +} \ No newline at end of file diff --git a/rede-anel-estelar/rede-anel-estelar-tutorial.pdf b/rede-anel-estelar/rede-anel-estelar-tutorial.pdf new file mode 100644 index 0000000..688f2ff Binary files /dev/null and b/rede-anel-estelar/rede-anel-estelar-tutorial.pdf differ diff --git a/rede-anel-estelar/rede-anel-estelar-tutorial.tex b/rede-anel-estelar/rede-anel-estelar-tutorial.tex new file mode 100644 index 0000000..7b70f24 --- /dev/null +++ b/rede-anel-estelar/rede-anel-estelar-tutorial.tex @@ -0,0 +1,22 @@ +\documentclass[10pt]{article} +\usepackage[utf8]{inputenc} +\usepackage{amsmath,amsthm,amssymb} +\usepackage{fullpage} +\usepackage{url} +\pagenumbering{gobble} +\usepackage{hyperref} + +\title{ Tutorial: Rede Anel Estelar} +\author{Arthur Andrade Dolival} +\date{} +\begin{document} +\maketitle +A verificação desta topologia de rede exige validar se a estrutura possui exatamente um anel central (ciclo simples) com tamanho mínimo de 3 nós, onde cada nó do anel distribui sinal para uma sub-rede sem ciclos (árvore). + +Em termos de teoria dos grafos, para que um grafo não direcionado finito represente exatamente essa arquitetura, ele deve satisfazer simultaneamente dois critérios fundamentais: +\begin{itemize} + \item A rede deve ser totalmente \textbf{conexa}, ou seja, deve ser possível enviar dados de qualquer roteador para qualquer outro roteador da rede (nenhuma sub-rede pode estar isolada). + \item O número total de roteadores deve ser \textbf{exatamente igual} ao número total de canais ativos (\( n = m \)). +\end{itemize} + +Se o grafo possuir \( n = m \), for totalmente conexo e tiver \( n \ge 3 \), ele terá estruturalmente apenas um ciclo simples com árvores acopladas a ele, o que valida o sistema com a saída \texttt{ONLINE}. Caso contrário, a topologia é inválida e a resposta será \texttt{NO}.\end{document} diff --git a/rede-anel-estelar/rede-anel-estelar.pdf b/rede-anel-estelar/rede-anel-estelar.pdf new file mode 100644 index 0000000..8d90350 Binary files /dev/null and b/rede-anel-estelar/rede-anel-estelar.pdf differ diff --git a/rede-anel-estelar/rede-anel-estelar.tex b/rede-anel-estelar/rede-anel-estelar.tex new file mode 100644 index 0000000..dacc34f --- /dev/null +++ b/rede-anel-estelar/rede-anel-estelar.tex @@ -0,0 +1,70 @@ +\documentclass{maratona} + +\begin{document} +\begin{ProblemaAutor}{}{Rede Anel Estelar}{1}{256}{Arthur Andrade Dolival} + +A Agência Espacial de Algoritmia está implementando uma nova infraestrutura de comunicação global baseada em criptografia quântica. +Para garantir a estabilidade do sistema, a arquitetura da rede deve seguir um padrão de topologia muito estrito, denominado \textbf{Rede Anel-Estelar Conexa}. + +O monitoramento da rede gerou um relatório contendo a topologia atualizada do sistema, representada por um grafo não direcionado com \( n \) roteadores quânticos, e \( m \) canais de fibra ótica. + +Os engenheiros de rede precisam determinar se a topologia atual atende perfeitamente às especificações de uma Rede Anel-Estelar Conexa. + +Formalmente, uma topologia é considerada válida se o grafo puder ser decomposto em um \textbf{conjunto de três ou mais árvores enraizadas, cujas raízes estão interconectadas por um único ciclo simples}, formando uma única componente conexa. +O ciclo simples representa o anel de sincronização principal, \textit{backbone}, e as árvores representam as sub-redes locais de distribuição que se ramificam a partir dos nós principais. + +É garantido que o grafo não contém canais redundantes, isso é, mais de uma conexão entre um mesmo par de roteadores, e nem conexões de um roteador consigo mesmo. + +\begin{figure}[h] + \centering + \includegraphics[width=0.7\textwidth]{image.png} + \caption{Exemplo da topologia de uma Rede Anel-Estelar Conexa, com os roteadores que compõem o \textit{backbone} em amarelo.} +\end{figure} + +\Entrada + +A primeira linha contém dois inteiros: \( n \) (\( 1 \le n \le 100 \)), representando o número de vértices, e \( m \) (\( 0 \le m \le \frac{n(n-1)}{2} \)), representando o número de arestas do grafo. + +Cada uma das \( m \) linhas seguintes contém um par de inteiros \( x \) e \( y \) (\( 1 \le x, y \le n \), \( x \neq y \)), indicando que existe uma aresta conectando os vértices \( x \) e \( y \). + +É garantido que para cada par de vértices haverá no máximo uma única aresta ligando-os e nenhuma aresta conecta um vértice a si mesmo. + +\Saida + +Se a topologia atual corresponder perfeitamente às especificações de uma Rede Estrela-Anel Conexa, imprima o código de validação do sistema: \texttt{ONLINE}. + +Caso contrário, imprima \texttt{OFFLINE}. + +\ExemploEntrada +\begin{Exemplo} +\texttt{14~14} & \texttt{ONLINE}\\ +\texttt{10~1} & \\ +\texttt{10~7} & \\ +\texttt{3~8} & \\ +\texttt{10~13} & \\ +\texttt{13~7} & \\ +\texttt{12~5} & \\ +\texttt{8~2} & \\ +\texttt{2~13} & \\ +\texttt{14~1} & \\ +\texttt{9~1} & \\ +\texttt{11~4} & \\ +\texttt{12~4} & \\ +\texttt{4~7} & \\ +\texttt{6~8} & \\ +\rowcolor{gray!20}\texttt{3~3} & \texttt{ONLINE}\\ +\rowcolor{gray!20}\texttt{2~3} & \\ +\rowcolor{gray!20}\texttt{1~3} & \\ +\rowcolor{gray!20}\texttt{1~2} & \\ +\texttt{4~3} & \texttt{OFFLINE}\\ +\texttt{3~1} & \\ +\texttt{4~2} & \\ +\texttt{1~2} & \\ +\end{Exemplo} + + + +\Notas + +Problema adaptado de \href{https://codeforces.com/problemset/problem/104/C}{Codeforces Beta Round 80 (Div. 2 Only, Problem C)}.\end{ProblemaAutor} +\end{document} diff --git a/rede-anel-estelar/src/ac.cpp b/rede-anel-estelar/src/ac.cpp new file mode 100644 index 0000000..1b33629 --- /dev/null +++ b/rede-anel-estelar/src/ac.cpp @@ -0,0 +1,52 @@ +// https://codeforces.com/problemset/problem/104/C +#include + +using namespace std; +using vi = vector; +using ll = long long; + +const int MAXN = 110; +vector g(MAXN); +bitset vis; + +void dfs(int x){ + vis[x]=1; + for(auto n: g[x]) if(!vis[n]) dfs(n); +} + +void solve() +{ + int n, m; cin >> n >> m; + + for (int i=0;i>u>>v; + g[u].push_back(v); + g[v].push_back(u); + } + + if (n != m) { + cout << "OFFLINE" << endl; + return; + } + + vis.reset(); + dfs(1); + for (int i=1;i<=n;i++){ + if (!vis[i]) { + cout << "OFFLINE" << endl; + return; + } + } + + cout << "ONLINE" << endl; + + return; +} + +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); cout.tie(0); + solve(); + return 0; +} \ No newline at end of file diff --git a/rede-anel-estelar/src/alternative-ac.py b/rede-anel-estelar/src/alternative-ac.py new file mode 100644 index 0000000..de91f1f --- /dev/null +++ b/rede-anel-estelar/src/alternative-ac.py @@ -0,0 +1,60 @@ +from collections import deque + + +def check_connectivity(adj, n): + vis = [False for _ in range(n)] + def dfs(x): + vis[x] = True + for v in adj[x]: + if not vis[v]: + dfs(v) + dfs(0) + return all(vis) + + +def check_cthulhu(adj, degree, n): + marked = [False for _ in range(n)] + dq = deque([]) + for i, d in enumerate(degree): + if d == 1: + dq.append(i) + marked[i] = True + + while len(dq) != 0: + i = dq.popleft() + for v in adj[i]: + if not marked[v]: + degree[v] -= 1 + if degree[v] == 1: + dq.append(v) + marked[v] = True + + # if all are marked it means that there was no cycle + if all(marked): + return False + + # if some of the non-marked vertices does not have degree 2, it is not a simple cycle + for v in range(n): + if not marked[v] and degree[v] != 2: + return False + + return True + + +n, m = map(int, input().split()) +adj = [[] for _ in range(n)] +degree = [0] * n + +for i in range(m): + u, v = map(int, input().split()) + u -= 1 + v -= 1 + adj[u].append(v) + adj[v].append(u) + degree[u] += 1 + degree[v] += 1 + +if not check_connectivity(adj, n) or not check_cthulhu(adj, degree, n): + print("OFFLINE") +else: + print("ONLINE") \ No newline at end of file diff --git a/rede-anel-estelar/src/checker.cpp b/rede-anel-estelar/src/checker.cpp new file mode 100644 index 0000000..3d9eeb4 --- /dev/null +++ b/rede-anel-estelar/src/checker.cpp @@ -0,0 +1,26 @@ +#include "testlib.h" +#include + +using namespace std; + +const string YES = "ONLINE"; +const string NO = "OFFLINE"; + +int main(int argc, char *argv[]) { + setName("%s", (YES + " or " + NO + " (case insensitive)").c_str()); + registerTestlibCmd(argc, argv); + + std::string ja = upperCase(ans.readWord()); + std::string pa = upperCase(ouf.readWord()); + + if (ja != YES && ja != NO) + quitf(_fail, "%s or %s expected in answer, but %s found", YES.c_str(), NO.c_str(), compress(ja).c_str()); + + if (pa != YES && pa != NO) + quitf(_pe, "%s or %s expected, but %s found", YES.c_str(), NO.c_str(), compress(pa).c_str()); + + if (ja != pa) + quitf(_wa, "expected %s, found %s", compress(ja).c_str(), compress(pa).c_str()); + + quitf(_ok, "answer is %s", ja.c_str()); +} \ No newline at end of file diff --git a/rede-anel-estelar/src/generator.cpp b/rede-anel-estelar/src/generator.cpp new file mode 100644 index 0000000..b11235a --- /dev/null +++ b/rede-anel-estelar/src/generator.cpp @@ -0,0 +1,172 @@ +#include "testlib.h" +#include + +using namespace std; + +const int MIN_N = 1; +const int MAX_N = 100; +const int rnd_test_n = 100; + +template void append(vector &dest, const vector &orig) { + dest.insert(dest.end(), orig.begin(), orig.end()); +} + +string output_tc(int n, int m, vector> &edges) { + ostringstream oss; + oss << n << " " << m << "\n"; + + vector p(n + 1); + iota(p.begin(), p.end(), 0); + shuffle(p.begin() + 1, p.end()); + + shuffle(edges.begin(), edges.end()); + + for (const auto &edge : edges) { + int u = edge.first; + int v = edge.second; + if (rnd.next(2)) swap(u, v); + oss << p[u] << " " << p[v] << "\n"; + } + return oss.str(); +} + +vector> generate_random_tree(int n) { + vector> edges; + for (int i = 2; i <= n; i++) { + int parent = rnd.next(1, i - 1); + edges.push_back({parent, i}); + } + return edges; +} + +string generate_valid_case(int n) { + if (n < 3) n = 3; + vector> edges; + + int k = rnd.next(3, n); + for (int i = 1; i <= k; i++) { + int next_node = (i == k) ? 1 : i + 1; + edges.push_back({i, next_node}); + } + + for (int i = k + 1; i <= n; i++) { + int parent = rnd.next(1, i - 1); + edges.push_back({parent, i}); + } + + return output_tc(n, edges.size(), edges); +} + +vector generate_sample_tests() { + vector tests; + vector> edges = { + {2, 3}, {1, 3}, {2, 1}, {3, 4}, {4, 5}, + {4, 6}, {2, 7}, {7, 8}, {7, 9}, {1, 10}, + {10, 11}, {11, 12}, {14, 9}, {13, 11} + }; + tests.push_back(output_tc(14, 14, edges)); + + vector> e1 = {{1, 2}, {2, 3}, {3, 1}}; + tests.push_back(output_tc(3, 3, e1)); + + vector> e2 = {{1, 2}, {2, 3}, {3, 4}}; + tests.push_back(output_tc(4, 3, e2)); + + return tests; +} + +vector generate_manual_tests() { + vector tests; + + vector> e1 = {{1, 2}, {2, 3}}; + tests.push_back(output_tc(3, 2, e1)); + + return tests; +} + +string rnd_test(int i) { + int max_n = MAX_N; + if (i < rnd_test_n / 3) max_n = 8; + else if (i < rnd_test_n / 2) max_n = 30; + + int n = rnd.next(3, max_n); + + if (rnd.next(2)) { + return generate_valid_case(n); + } else { + int m_type = rnd.next(3); + vector> edges; + + if (m_type == 0) { + edges = generate_random_tree(n); + } else if (m_type == 1) { + edges = generate_random_tree(n); + + int max_possible_edges = n * (n - 1) / 2; + int edges_to_add = min(6, max_possible_edges - (n - 1)); + + set> existing; + for (auto &e : edges) { + existing.insert({min(e.first, e.second), max(e.first, e.second)}); + } + + while (edges_to_add > 0) { + int u = rnd.next(1, n); + int v = rnd.next(1, n); + if (u != v) { + pair new_edge = {min(u, v), max(u, v)}; + if (existing.find(new_edge) == existing.end()) { + existing.insert(new_edge); + edges.push_back(new_edge); + edges_to_add--; + } + } + } + } else { + if (n < 6) n = 6; + int metade = n / 2; + for (int k = 1; k <= metade; k++) { + edges.push_back({k, (k == metade) ? 1 : k + 1}); + } + for (int k = metade + 1; k <= n; k++) { + edges.push_back({k, (k == n) ? metade + 1 : k + 1}); + } + } + return output_tc(n, edges.size(), edges); + } +} + +vector generate_random_tests() { + vector tests; + for (int i = 0; i < rnd_test_n; i++) { + tests.push_back(rnd_test(i)); + } + return tests; +} + +string extreme_test_1() { + return generate_valid_case(MAX_N); +} + +vector generate_extreme_tests() { + vector tests; + tests.push_back(extreme_test_1()); + return tests; +} + +int main(int argc, char *argv[]) { + registerGen(argc, argv, 1); + vector tests; + size_t test = 0; + + append(tests, generate_sample_tests()); + append(tests, generate_manual_tests()); + append(tests, generate_random_tests()); + append(tests, generate_extreme_tests()); + + for (const auto &t : tests) { + startTest(++test); + cout << t; + } + return 0; +} \ No newline at end of file diff --git a/rede-anel-estelar/src/script.sh b/rede-anel-estelar/src/script.sh new file mode 100644 index 0000000..a8a6bda --- /dev/null +++ b/rede-anel-estelar/src/script.sh @@ -0,0 +1 @@ +generator \ No newline at end of file diff --git a/rede-anel-estelar/src/testlib.h b/rede-anel-estelar/src/testlib.h new file mode 100644 index 0000000..fac02ad --- /dev/null +++ b/rede-anel-estelar/src/testlib.h @@ -0,0 +1,5963 @@ +/* + * It is strictly recommended to include "testlib.h" before any other include + * in your code. In this case testlib overrides compiler specific "random()". + * + * If you can't compile your code and compiler outputs something about + * ambiguous call of "random_shuffle", "rand" or "srand" it means that + * you shouldn't use them. Use "shuffle", and "rnd.next()" instead of them + * because these calls produce stable result for any C++ compiler. Read + * sample generator sources for clarification. + * + * Please read the documentation for class "random_t" and use "rnd" instance in + * generators. Probably, these sample calls will be usefull for you: + * rnd.next(); rnd.next(100); rnd.next(1, 2); + * rnd.next(3.14); rnd.next("[a-z]{1,100}"). + * + * Also read about wnext() to generate off-center random distribution. + * + * See https://github.com/MikeMirzayanov/testlib/ to get latest version or bug tracker. + */ + +#ifndef _TESTLIB_H_ +#define _TESTLIB_H_ + +/* + * Copyright (c) 2005-2022 + */ + +#define VERSION "0.9.40-SNAPSHOT" + +/* + * Mike Mirzayanov + * + * This material is provided "as is", with absolutely no warranty expressed + * or implied. Any use is at your own risk. + * + * Permission to use or copy this software for any purpose is hereby granted + * without fee, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + * + */ + +/* NOTE: This file contains testlib library for C++. + * + * Check, using testlib running format: + * check.exe [ [-appes]], + * If result file is specified it will contain results. + * + * Validator, using testlib running format: + * validator.exe < input.txt, + * It will return non-zero exit code and writes message to standard output. + * + * Generator, using testlib running format: + * gen.exe [parameter-1] [parameter-2] [... paramerter-n] + * You can write generated test(s) into standard output or into the file(s). + * + * Interactor, using testlib running format: + * interactor.exe [ [ [-appes]]], + * Reads test from inf (mapped to args[1]), writes result to tout (mapped to argv[2], + * can be judged by checker later), reads program output from ouf (mapped to stdin), + * writes output to program via stdout (use cout, printf, etc). + */ + +const char *latestFeatures[] = { + "Supported '--testMarkupFileName fn' and '--testCase tc/--testCaseFileName fn' for validators", + "Added opt defaults via opt(key/index, default_val); check unused opts when using has_opt or default opt (turn off this check with suppressEnsureNoUnusedOpt()).", + "For checker added --group and --testset command line params (like for validator), use checker.group() or checker.testset() to get values", + "Added quitpi(points_info, message) function to return with _points exit code 7 and given points_info", + "rnd.partition(size, sum[, min_part=1]) returns random (unsorted) partition which is a representation of the given `sum` as a sum of `size` positive integers (or >=min_part if specified)", + "rnd.distinct(size, n) and rnd.distinct(size, from, to)", + "opt(\"some_missing_key\") returns false now", + "has_opt(key)", + "Abort validator on validator.testset()/validator.group() if registered without using command line", + "Print integer range violations in a human readable way like `violates the range [1, 10^9]`", + "Opts supported: use them like n = opt(\"n\"), in a command line you can use an exponential notation", + "Reformatted", + "Use setTestCase(i) or unsetTestCase() to support test cases (you can use it in any type of program: generator, interactor, validator or checker)", + "Fixed issue #87: readStrictDouble accepts \"-0.00\"", + "Fixed issue #83: added InStream::quitif(condition, ...)", + "Fixed issue #79: fixed missed guard against repeated header include", + "Fixed issue #80: fixed UB in case of huge quitf message", + "Fixed issue #84: added readXs(size, indexBase = 1)", + "Fixed stringstream repeated usage issue", + "Fixed compilation in g++ (for std=c++03)", + "Batch of println functions (support collections, iterator ranges)", + "Introduced rnd.perm(size, first = 0) to generate a `first`-indexed permutation", + "Allow any whitespace in readInts-like functions for non-validators", + "Ignore 4+ command line arguments ifdef EJUDGE", + "Speed up of vtos", + "Show line number in validators in case of incorrect format", + "Truncate huge checker/validator/interactor message", + "Fixed issue with readTokenTo of very long tokens, now aborts with _pe/_fail depending of a stream type", + "Introduced InStream::ensure/ensuref checking a condition, returns wa/fail depending of a stream type", + "Fixed compilation in VS 2015+", + "Introduced space-separated read functions: readWords/readTokens, multilines read functions: readStrings/readLines", + "Introduced space-separated read functions: readInts/readIntegers/readLongs/readUnsignedLongs/readDoubles/readReals/readStrictDoubles/readStrictReals", + "Introduced split/tokenize functions to separate string by given char", + "Introduced InStream::readUnsignedLong and InStream::readLong with unsigned long long paramerters", + "Supported --testOverviewLogFileName for validator: bounds hits + features", + "Fixed UB (sequence points) in random_t", + "POINTS_EXIT_CODE returned back to 7 (instead of 0)", + "Removed disable buffers for interactive problems, because it works unexpectedly in wine", + "InStream over string: constructor of InStream from base InStream to inherit policies and std::string", + "Added expectedButFound quit function, examples: expectedButFound(_wa, 10, 20), expectedButFound(_fail, ja, pa, \"[n=%d,m=%d]\", n, m)", + "Fixed incorrect interval parsing in patterns", + "Use registerGen(argc, argv, 1) to develop new generator, use registerGen(argc, argv, 0) to compile old generators (originally created for testlib under 0.8.7)", + "Introduced disableFinalizeGuard() to switch off finalization checkings", + "Use join() functions to format a range of items as a single string (separated by spaces or other separators)", + "Use -DENABLE_UNEXPECTED_EOF to enable special exit code (by default, 8) in case of unexpected eof. It is good idea to use it in interactors", + "Use -DUSE_RND_AS_BEFORE_087 to compile in compatibility mode with random behavior of versions before 0.8.7", + "Fixed bug with nan in stringToDouble", + "Fixed issue around overloads for size_t on x64", + "Added attribute 'points' to the XML output in case of result=_points", + "Exit codes can be customized via macros, e.g. -DPE_EXIT_CODE=14", + "Introduced InStream function readWordTo/readTokenTo/readStringTo/readLineTo for faster reading", + "Introduced global functions: format(), englishEnding(), upperCase(), lowerCase(), compress()", + "Manual buffer in InStreams, some IO speed improvements", + "Introduced quitif(bool, const char* pattern, ...) which delegates to quitf() in case of first argument is true", + "Introduced guard against missed quitf() in checker or readEof() in validators", + "Supported readStrictReal/readStrictDouble - to use in validators to check strictly float numbers", + "Supported registerInteraction(argc, argv)", + "Print checker message to the stderr instead of stdout", + "Supported TResult _points to output calculated score, use quitp(...) functions", + "Fixed to be compilable on Mac", + "PC_BASE_EXIT_CODE=50 in case of defined TESTSYS", + "Fixed issues 19-21, added __attribute__ format printf", + "Some bug fixes", + "ouf.readInt(1, 100) and similar calls return WA", + "Modified random_t to avoid integer overflow", + "Truncated checker output [patch by Stepan Gatilov]", + "Renamed class random -> class random_t", + "Supported name parameter for read-and-validation methods, like readInt(1, 2, \"n\")", + "Fixed bug in readDouble()", + "Improved ensuref(), fixed nextLine to work in case of EOF, added startTest()", + "Supported \"partially correct\", example: quitf(_pc(13), \"result=%d\", result)", + "Added shuffle(begin, end), use it instead of random_shuffle(begin, end)", + "Added readLine(const string& ptrn), fixed the logic of readLine() in the validation mode", + "Package extended with samples of generators and validators", + "Written the documentation for classes and public methods in testlib.h", + "Implemented random routine to support generators, use registerGen() to switch it on", + "Implemented strict mode to validate tests, use registerValidation() to switch it on", + "Now ncmp.cpp and wcmp.cpp are return WA if answer is suffix or prefix of the output", + "Added InStream::readLong() and removed InStream::readLongint()", + "Now no footer added to each report by default (use directive FOOTER to switch on)", + "Now every checker has a name, use setName(const char* format, ...) to set it", + "Now it is compatible with TTS (by Kittens Computing)", + "Added \'ensure(condition, message = \"\")\' feature, it works like assert()", + "Fixed compatibility with MS C++ 7.1", + "Added footer with exit code information", + "Added compatibility with EJUDGE (compile with EJUDGE directive)", + "Added compatibility with Contester (compile with CONTESTER directive)" +}; + +#ifdef _MSC_VER +#define _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_WARNINGS +#define _CRT_NO_VA_START_VALIDATION +#endif + +/* Overrides random() for Borland C++. */ +#define random __random_deprecated +#include +#include +#include +#include +#undef random + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT +# include +#endif + +#if (_WIN32 || __WIN32__ || __WIN32 || _WIN64 || __WIN64__ || __WIN64 || WINNT || __WINNT || __WINNT__ || __CYGWIN__) +# if !defined(_MSC_VER) || _MSC_VER > 1400 +# define NOMINMAX 1 +# include +# else +# define WORD unsigned short +# include +# endif +# include +# define ON_WINDOWS +# if defined(_MSC_VER) && _MSC_VER > 1400 +# pragma warning( disable : 4127 ) +# pragma warning( disable : 4146 ) +# pragma warning( disable : 4458 ) +# endif +#else +# define WORD unsigned short +# include +#endif + +#if defined(FOR_WINDOWS) && defined(FOR_LINUX) +#error Only one target system is allowed +#endif + +#ifndef LLONG_MIN +#define LLONG_MIN (-9223372036854775807LL - 1) +#endif + +#ifndef ULLONG_MAX +#define ULLONG_MAX (18446744073709551615) +#endif + +#define LF ((char)10) +#define CR ((char)13) +#define TAB ((char)9) +#define SPACE ((char)' ') +#define EOFC (255) + +#ifndef OK_EXIT_CODE +# ifdef CONTESTER +# define OK_EXIT_CODE 0xAC +# elif defined BOCA_SUPPORT +# define OK_EXIT_CODE 4 +# else +# define OK_EXIT_CODE 0 +# endif +#endif + +#ifndef WA_EXIT_CODE +# ifdef EJUDGE +# define WA_EXIT_CODE 5 +# elif defined(CONTESTER) +# define WA_EXIT_CODE 0xAB +# elif defined BOCA_SUPPORT +# define WA_EXIT_CODE 6 +# else +# define WA_EXIT_CODE 1 +# endif +#endif + +#ifndef PE_EXIT_CODE +# ifdef EJUDGE +# define PE_EXIT_CODE 4 +# elif defined(CONTESTER) +# define PE_EXIT_CODE 0xAA +# elif defined BOCA_SUPPORT +# define PE_EXIT_CODE 6 +# else +# define PE_EXIT_CODE 2 +# endif +#endif + +#ifndef FAIL_EXIT_CODE +# ifdef EJUDGE +# define FAIL_EXIT_CODE 6 +# elif defined(CONTESTER) +# define FAIL_EXIT_CODE 0xA3 +# elif defined BOCA_SUPPORT +# define FAIL_EXIT_CODE 7 +# else +# define FAIL_EXIT_CODE 3 +# endif +#endif + +#ifndef DIRT_EXIT_CODE +# ifdef EJUDGE +# define DIRT_EXIT_CODE 6 +# else +# define DIRT_EXIT_CODE 4 +# endif +#endif + +#ifndef POINTS_EXIT_CODE +# ifndef BOCA_SUPPORT +# define POINTS_EXIT_CODE 7 +# else +# define POINTS_EXIT_CODE 5 +# endif +#endif + +#ifndef UNEXPECTED_EOF_EXIT_CODE +# define UNEXPECTED_EOF_EXIT_CODE 8 +#endif + +#ifndef PC_BASE_EXIT_CODE +# ifdef TESTSYS +# define PC_BASE_EXIT_CODE 50 +# else +# define PC_BASE_EXIT_CODE 0 +# endif +#endif + +#ifdef __GNUC__ +# define __TESTLIB_STATIC_ASSERT(condition) typedef void* __testlib_static_assert_type[(condition) ? 1 : -1] __attribute__((unused)) +#else +# define __TESTLIB_STATIC_ASSERT(condition) typedef void* __testlib_static_assert_type[(condition) ? 1 : -1] +#endif + +#ifdef ON_WINDOWS +#define I64 "%I64d" +#define U64 "%I64u" +#else +#define I64 "%lld" +#define U64 "%llu" +#endif + +#ifdef _MSC_VER +# define NORETURN __declspec(noreturn) +#elif defined __GNUC__ +# define NORETURN __attribute__ ((noreturn)) +#else +# define NORETURN +#endif + +static char __testlib_format_buffer[16777216]; +static int __testlib_format_buffer_usage_count = 0; + +#define FMT_TO_RESULT(fmt, cstr, result) std::string result; \ + if (__testlib_format_buffer_usage_count != 0) \ + __testlib_fail("FMT_TO_RESULT::__testlib_format_buffer_usage_count != 0"); \ + __testlib_format_buffer_usage_count++; \ + va_list ap; \ + va_start(ap, fmt); \ + vsnprintf(__testlib_format_buffer, sizeof(__testlib_format_buffer), cstr, ap); \ + va_end(ap); \ + __testlib_format_buffer[sizeof(__testlib_format_buffer) - 1] = 0; \ + result = std::string(__testlib_format_buffer); \ + __testlib_format_buffer_usage_count--; \ + +const long long __TESTLIB_LONGLONG_MAX = 9223372036854775807LL; +const int __TESTLIB_MAX_TEST_CASE = 1073741823; + +int __testlib_exitCode; + +bool __testlib_hasTestCase; +int __testlib_testCase = -1; + +void setTestCase(int testCase); + +void unsetTestCase() { + __testlib_hasTestCase = false; + __testlib_testCase = -1; +} + +NORETURN static void __testlib_fail(const std::string &message); + +template +static inline T __testlib_abs(const T &x) { + return x > 0 ? x : -x; +} + +template +static inline T __testlib_min(const T &a, const T &b) { + return a < b ? a : b; +} + +template +static inline T __testlib_max(const T &a, const T &b) { + return a > b ? a : b; +} + +template +static inline T __testlib_crop(T value, T a, T b) { + return __testlib_min(__testlib_max(value, a), --b); +} + +static inline double __testlib_crop(double value, double a, double b) { + value = __testlib_min(__testlib_max(value, a), b); + if (value >= b) + value = std::nexttoward(b, a); + return value; +} + +static bool __testlib_prelimIsNaN(double r) { + volatile double ra = r; +#ifndef __BORLANDC__ + return ((ra != ra) == true) && ((ra == ra) == false) && ((1.0 > ra) == false) && ((1.0 < ra) == false); +#else + return std::_isnan(ra); +#endif +} + +static std::string removeDoubleTrailingZeroes(std::string value) { + while (!value.empty() && value[value.length() - 1] == '0' && value.find('.') != std::string::npos) + value = value.substr(0, value.length() - 1); + if (!value.empty() && value[value.length() - 1] == '.') + return value + '0'; + else + return value; +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 1, 2))) +#endif +std::string format(const char *fmt, ...) { + FMT_TO_RESULT(fmt, fmt, result); + return result; +} + +std::string format(const std::string fmt, ...) { + FMT_TO_RESULT(fmt, fmt.c_str(), result); + return result; +} + +static std::string __testlib_part(const std::string &s); + +static bool __testlib_isNaN(double r) { + __TESTLIB_STATIC_ASSERT(sizeof(double) == sizeof(long long)); + volatile double ra = r; + long long llr1, llr2; + std::memcpy((void *) &llr1, (void *) &ra, sizeof(double)); + ra = -ra; + std::memcpy((void *) &llr2, (void *) &ra, sizeof(double)); + long long llnan = 0xFFF8000000000000LL; + return __testlib_prelimIsNaN(r) || llnan == llr1 || llnan == llr2; +} + +static double __testlib_nan() { + __TESTLIB_STATIC_ASSERT(sizeof(double) == sizeof(long long)); +#ifndef NAN + long long llnan = 0xFFF8000000000000LL; + double nan; + std::memcpy(&nan, &llnan, sizeof(double)); + return nan; +#else + return NAN; +#endif +} + +static bool __testlib_isInfinite(double r) { + volatile double ra = r; + return (ra > 1E300 || ra < -1E300); +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +inline bool doubleCompare(double expected, double result, double MAX_DOUBLE_ERROR) { + MAX_DOUBLE_ERROR += 1E-15; + if (__testlib_isNaN(expected)) { + return __testlib_isNaN(result); + } else if (__testlib_isInfinite(expected)) { + if (expected > 0) { + return result > 0 && __testlib_isInfinite(result); + } else { + return result < 0 && __testlib_isInfinite(result); + } + } else if (__testlib_isNaN(result) || __testlib_isInfinite(result)) { + return false; + } else if (__testlib_abs(result - expected) <= MAX_DOUBLE_ERROR) { + return true; + } else { + double minv = __testlib_min(expected * (1.0 - MAX_DOUBLE_ERROR), + expected * (1.0 + MAX_DOUBLE_ERROR)); + double maxv = __testlib_max(expected * (1.0 - MAX_DOUBLE_ERROR), + expected * (1.0 + MAX_DOUBLE_ERROR)); + return result >= minv && result <= maxv; + } +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +inline double doubleDelta(double expected, double result) { + double absolute = __testlib_abs(result - expected); + + if (__testlib_abs(expected) > 1E-9) { + double relative = __testlib_abs(absolute / expected); + return __testlib_min(absolute, relative); + } else + return absolute; +} + +/** It does nothing on non-windows and files differ from stdin/stdout/stderr. */ +static void __testlib_set_binary(std::FILE *file) { + if (NULL != file) { +#ifdef ON_WINDOWS +# ifdef _O_BINARY + if (stdin == file) +# ifdef STDIN_FILENO + return void(_setmode(STDIN_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stdin), _O_BINARY)); +# endif + if (stdout == file) +# ifdef STDOUT_FILENO + return void(_setmode(STDOUT_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stdout), _O_BINARY)); +# endif + if (stderr == file) +# ifdef STDERR_FILENO + return void(_setmode(STDERR_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stderr), _O_BINARY)); +# endif +# elif O_BINARY + if (stdin == file) +# ifdef STDIN_FILENO + return void(setmode(STDIN_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stdin), O_BINARY)); +# endif + if (stdout == file) +# ifdef STDOUT_FILENO + return void(setmode(STDOUT_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stdout), O_BINARY)); +# endif + if (stderr == file) +# ifdef STDERR_FILENO + return void(setmode(STDERR_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stderr), O_BINARY)); +# endif +# endif +#endif + } +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +template +static std::string vtos(const T &t, std::true_type) { + if (t == 0) + return "0"; + else { + T n(t); + bool negative = n < 0; + std::string s; + while (n != 0) { + T digit = n % 10; + if (digit < 0) + digit = -digit; + s += char('0' + digit); + n /= 10; + } + std::reverse(s.begin(), s.end()); + return negative ? "-" + s : s; + } +} + +template +static std::string vtos(const T &t, std::false_type) { + std::string s; + static std::stringstream ss; + ss.str(std::string()); + ss.clear(); + ss << t; + ss >> s; + return s; +} + +template +static std::string vtos(const T &t) { + return vtos(t, std::is_integral()); +} + +/* signed case. */ +template +static std::string toHumanReadableString(const T &n, std::false_type) { + if (n == 0) + return vtos(n); + int trailingZeroCount = 0; + T n_ = n; + while (n_ % 10 == 0) + n_ /= 10, trailingZeroCount++; + if (trailingZeroCount >= 7) { + if (n_ == 1) + return "10^" + vtos(trailingZeroCount); + else if (n_ == -1) + return "-10^" + vtos(trailingZeroCount); + else + return vtos(n_) + "*10^" + vtos(trailingZeroCount); + } else + return vtos(n); +} + +/* unsigned case. */ +template +static std::string toHumanReadableString(const T &n, std::true_type) { + if (n == 0) + return vtos(n); + int trailingZeroCount = 0; + T n_ = n; + while (n_ % 10 == 0) + n_ /= 10, trailingZeroCount++; + if (trailingZeroCount >= 7) { + if (n_ == 1) + return "10^" + vtos(trailingZeroCount); + else + return vtos(n_) + "*10^" + vtos(trailingZeroCount); + } else + return vtos(n); +} + +template +static std::string toHumanReadableString(const T &n) { + return toHumanReadableString(n, std::is_unsigned()); +} +#else +template +static std::string vtos(const T& t) +{ + std::string s; + static std::stringstream ss; + ss.str(std::string()); + ss.clear(); + ss << t; + ss >> s; + return s; +} + +template +static std::string toHumanReadableString(const T &n) { + return vtos(n); +} +#endif + +template +static std::string toString(const T &t) { + return vtos(t); +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +/* opts */ +void prepareOpts(int argc, char* argv[]); +#endif + +/* + * Very simple regex-like pattern. + * It used for two purposes: validation and generation. + * + * For example, pattern("[a-z]{1,5}").next(rnd) will return + * random string from lowercase latin letters with length + * from 1 to 5. It is easier to call rnd.next("[a-z]{1,5}") + * for the same effect. + * + * Another samples: + * "mike|john" will generate (match) "mike" or "john"; + * "-?[1-9][0-9]{0,3}" will generate (match) non-zero integers from -9999 to 9999; + * "id-([ac]|b{2})" will generate (match) "id-a", "id-bb", "id-c"; + * "[^0-9]*" will match sequences (empty or non-empty) without digits, you can't + * use it for generations. + * + * You can't use pattern for generation if it contains meta-symbol '*'. Also it + * is not recommended to use it for char-sets with meta-symbol '^' like [^a-z]. + * + * For matching very simple greedy algorithm is used. For example, pattern + * "[0-9]?1" will not match "1", because of greedy nature of matching. + * Alternations (meta-symbols "|") are processed with brute-force algorithm, so + * do not use many alternations in one expression. + * + * If you want to use one expression many times it is better to compile it into + * a single pattern like "pattern p("[a-z]+")". Later you can use + * "p.matches(std::string s)" or "p.next(random_t& rd)" to check matching or generate + * new string by pattern. + * + * Simpler way to read token and check it for pattern matching is "inf.readToken("[a-z]+")". + * + * All spaces are ignored in regex, unless escaped with \. For example, ouf.readLine("NO SOLUTION") + * will expect "NOSOLUTION", the correct call should be ouf.readLine("NO\\ SOLUTION") or + * ouf.readLine(R"(NO\ SOLUTION)") if you prefer raw string literals from C++11. + */ +class random_t; + +class pattern { +public: + /* Create pattern instance by string. */ + pattern(std::string s); + + /* Generate new string by pattern and given random_t. */ + std::string next(random_t &rnd) const; + + /* Checks if given string match the pattern. */ + bool matches(const std::string &s) const; + + /* Returns source string of the pattern. */ + std::string src() const; + +private: + bool matches(const std::string &s, size_t pos) const; + + std::string s; + std::vector children; + std::vector chars; + int from; + int to; +}; + +/* + * Use random_t instances to generate random values. It is preffered + * way to use randoms instead of rand() function or self-written + * randoms. + * + * Testlib defines global variable "rnd" of random_t class. + * Use registerGen(argc, argv, 1) to setup random_t seed be command + * line (to use latest random generator version). + * + * Random generates uniformly distributed values if another strategy is + * not specified explicitly. + */ +class random_t { +private: + unsigned long long seed; + static const unsigned long long multiplier; + static const unsigned long long addend; + static const unsigned long long mask; + static const int lim; + + long long nextBits(int bits) { + if (bits <= 48) { + seed = (seed * multiplier + addend) & mask; + return (long long) (seed >> (48 - bits)); + } else { + if (bits > 63) + __testlib_fail("random_t::nextBits(int bits): n must be less than 64"); + + int lowerBitCount = (random_t::version == 0 ? 31 : 32); + + long long left = (nextBits(31) << 32); + long long right = nextBits(lowerBitCount); + + return left ^ right; + } + } + +public: + static int version; + + /* New random_t with fixed seed. */ + random_t() + : seed(3905348978240129619LL) { + } + + /* Sets seed by command line. */ + void setSeed(int argc, char *argv[]) { + random_t p; + + seed = 3905348978240129619LL; + for (int i = 1; i < argc; i++) { + std::size_t le = std::strlen(argv[i]); + for (std::size_t j = 0; j < le; j++) + seed = seed * multiplier + (unsigned int) (argv[i][j]) + addend; + seed += multiplier / addend; + } + + seed = seed & mask; + } + + /* Sets seed by given value. */ + void setSeed(long long _seed) { + _seed = (_seed ^ multiplier) & mask; + seed = _seed; + } + +#ifndef __BORLANDC__ + + /* Random string value by given pattern (see pattern documentation). */ + std::string next(const std::string &ptrn) { + pattern p(ptrn); + return p.next(*this); + } + +#else + /* Random string value by given pattern (see pattern documentation). */ + std::string next(std::string ptrn) + { + pattern p(ptrn); + return p.next(*this); + } +#endif + + /* Random value in range [0, n-1]. */ + int next(int n) { + if (n <= 0) + __testlib_fail("random_t::next(int n): n must be positive"); + + if ((n & -n) == n) // n is a power of 2 + return (int) ((n * (long long) nextBits(31)) >> 31); + + const long long limit = INT_MAX / n * n; + + long long bits; + do { + bits = nextBits(31); + } while (bits >= limit); + + return int(bits % n); + } + + /* Random value in range [0, n-1]. */ + unsigned int next(unsigned int n) { + if (n >= INT_MAX) + __testlib_fail("random_t::next(unsigned int n): n must be less INT_MAX"); + return (unsigned int) next(int(n)); + } + + /* Random value in range [0, n-1]. */ + long long next(long long n) { + if (n <= 0) + __testlib_fail("random_t::next(long long n): n must be positive"); + + const long long limit = __TESTLIB_LONGLONG_MAX / n * n; + + long long bits; + do { + bits = nextBits(63); + } while (bits >= limit); + + return bits % n; + } + + /* Random value in range [0, n-1]. */ + unsigned long long next(unsigned long long n) { + if (n >= (unsigned long long) (__TESTLIB_LONGLONG_MAX)) + __testlib_fail("random_t::next(unsigned long long n): n must be less LONGLONG_MAX"); + return (unsigned long long) next((long long) (n)); + } + + /* Random value in range [0, n-1]. */ + long next(long n) { + return (long) next((long long) (n)); + } + + /* Random value in range [0, n-1]. */ + unsigned long next(unsigned long n) { + if (n >= (unsigned long) (LONG_MAX)) + __testlib_fail("random_t::next(unsigned long n): n must be less LONG_MAX"); + return (unsigned long) next((unsigned long long) (n)); + } + + /* Returns random value in range [from,to]. */ + int next(int from, int to) { + return int(next((long long) to - from + 1) + from); + } + + /* Returns random value in range [from,to]. */ + unsigned int next(unsigned int from, unsigned int to) { + return (unsigned int) (next((long long) to - from + 1) + from); + } + + /* Returns random value in range [from,to]. */ + long long next(long long from, long long to) { + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + unsigned long long next(unsigned long long from, unsigned long long to) { + if (from > to) + __testlib_fail("random_t::next(unsigned long long from, unsigned long long to): from can't not exceed to"); + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + long next(long from, long to) { + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + unsigned long next(unsigned long from, unsigned long to) { + if (from > to) + __testlib_fail("random_t::next(unsigned long from, unsigned long to): from can't not exceed to"); + return next(to - from + 1) + from; + } + + /* Random double value in range [0, 1). */ + double next() { + long long left = ((long long) (nextBits(26)) << 27); + long long right = nextBits(27); + return __testlib_crop((double) (left + right) / (double) (1LL << 53), 0.0, 1.0); + } + + /* Random double value in range [0, n). */ + double next(double n) { + if (n <= 0.0) + __testlib_fail("random_t::next(double): n should be positive"); + return __testlib_crop(n * next(), 0.0, n); + } + + /* Random double value in range [from, to). */ + double next(double from, double to) { + if (from >= to) + __testlib_fail("random_t::next(double from, double to): from should be strictly less than to"); + return next(to - from) + from; + } + + /* Returns random element from container. */ + template + typename Container::value_type any(const Container &c) { + int size = int(c.size()); + if (size <= 0) + __testlib_fail("random_t::any(const Container& c): c.size() must be positive"); + return *(c.begin() + next(size)); + } + + /* Returns random element from iterator range. */ + template + typename Iter::value_type any(const Iter &begin, const Iter &end) { + int size = int(end - begin); + if (size <= 0) + __testlib_fail("random_t::any(const Iter& begin, const Iter& end): range must have positive length"); + return *(begin + next(size)); + } + + /* Random string value by given pattern (see pattern documentation). */ +#ifdef __GNUC__ + __attribute__ ((format (printf, 2, 3))) +#endif + std::string next(const char *format, ...) { + FMT_TO_RESULT(format, format, ptrn); + return next(ptrn); + } + + /* + * Weighted next. If type == 0 than it is usual "next()". + * + * If type = 1, than it returns "max(next(), next())" + * (the number of "max" functions equals to "type"). + * + * If type < 0, than "max" function replaces with "min". + */ + int wnext(int n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(int n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + int result = next(n); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next(n)); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next(n)); + + return result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop((int) (double(n) * p), 0, n); + } + } + + /* See wnext(int, int). It uses the same algorithms. */ + long long wnext(long long n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(long long n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + long long result = next(n); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next(n)); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next(n)); + + return result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop((long long) (double(n) * p), 0LL, n); + } + } + + /* Returns value in [0, n). See wnext(int, int). It uses the same algorithms. */ + double wnext(double n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(double n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + double result = next(); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next()); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next()); + + return n * result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop(n * p, 0.0, n); + } + } + + /* Returns value in [0, 1). See wnext(int, int). It uses the same algorithms. */ + double wnext(int type) { + return wnext(1.0, type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned int wnext(unsigned int n, int type) { + if (n >= INT_MAX) + __testlib_fail("random_t::wnext(unsigned int n, int type): n must be less INT_MAX"); + return (unsigned int) wnext(int(n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned long long wnext(unsigned long long n, int type) { + if (n >= (unsigned long long) (__TESTLIB_LONGLONG_MAX)) + __testlib_fail("random_t::wnext(unsigned long long n, int type): n must be less LONGLONG_MAX"); + + return (unsigned long long) wnext((long long) (n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + long wnext(long n, int type) { + return (long) wnext((long long) (n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned long wnext(unsigned long n, int type) { + if (n >= (unsigned long) (LONG_MAX)) + __testlib_fail("random_t::wnext(unsigned long n, int type): n must be less LONG_MAX"); + + return (unsigned long) wnext((unsigned long long) (n), type); + } + + /* Returns weighted random value in range [from, to]. */ + int wnext(int from, int to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(int from, int to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + int wnext(unsigned int from, unsigned int to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(unsigned int from, unsigned int to, int type): from can't not exceed to"); + return int(wnext(to - from + 1, type) + from); + } + + /* Returns weighted random value in range [from, to]. */ + long long wnext(long long from, long long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(long long from, long long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + unsigned long long wnext(unsigned long long from, unsigned long long to, int type) { + if (from > to) + __testlib_fail( + "random_t::wnext(unsigned long long from, unsigned long long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + long wnext(long from, long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(long from, long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + unsigned long wnext(unsigned long from, unsigned long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(unsigned long from, unsigned long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random double value in range [from, to). */ + double wnext(double from, double to, int type) { + if (from >= to) + __testlib_fail("random_t::wnext(double from, double to, int type): from should be strictly less than to"); + return wnext(to - from, type) + from; + } + + /* Returns weighted random element from container. */ + template + typename Container::value_type wany(const Container &c, int type) { + size_t size = c.size(); + if (size <= 0) + __testlib_fail("random_t::wany(const Container& c, int type): c.size() must be positive"); + return *(c.begin() + wnext(size, type)); + } + + /* Returns weighted random element from iterator range. */ + template + typename Iter::value_type wany(const Iter &begin, const Iter &end, int type) { + int size = int(end - begin); + if (size <= 0) + __testlib_fail( + "random_t::any(const Iter& begin, const Iter& end, int type): range must have positive length"); + return *(begin + wnext(size, type)); + } + + /* Returns random permutation of the given size (values are between `first` and `first`+size-1)*/ + template + std::vector perm(T size, E first) { + if (size < 0) + __testlib_fail("random_t::perm(T size, E first = 0): size must non-negative"); + else if (size == 0) + return std::vector(); + std::vector p(size); + E current = first; + for (T i = 0; i < size; i++) + p[i] = current++; + if (size > 1) + for (T i = 1; i < size; i++) + std::swap(p[i], p[next(i + 1)]); + return p; + } + + /* Returns random permutation of the given size (values are between 0 and size-1)*/ + template + std::vector perm(T size) { + return perm(size, T(0)); + } + + /* Returns `size` unordered (unsorted) distinct numbers between `from` and `to`. */ + template + std::vector distinct(int size, T from, T to) { + std::vector result; + if (size == 0) + return result; + + if (from > to) + __testlib_fail("random_t::distinct expected from <= to"); + + if (size < 0) + __testlib_fail("random_t::distinct expected size >= 0"); + + uint64_t n = to - from + 1; + if (uint64_t(size) > n) + __testlib_fail("random_t::distinct expected size <= to - from + 1"); + + double expected = 0.0; + for (int i = 1; i <= size; i++) + expected += double(n) / double(n - i + 1); + + if (expected < double(n)) { + std::set vals; + while (int(vals.size()) < size) { + T x = T(next(from, to)); + if (vals.insert(x).second) + result.push_back(x); + } + } else { + if (n > 1000000000) + __testlib_fail("random_t::distinct here expected to - from + 1 <= 1000000000"); + std::vector p(perm(int(n), from)); + result.insert(result.end(), p.begin(), p.begin() + size); + } + + return result; + } + + /* Returns `size` unordered (unsorted) distinct numbers between `0` and `upper`-1. */ + template + std::vector distinct(int size, T upper) { + if (size < 0) + __testlib_fail("random_t::distinct expected size >= 0"); + if (size == 0) + return std::vector(); + + if (upper <= 0) + __testlib_fail("random_t::distinct expected upper > 0"); + if (size > upper) + __testlib_fail("random_t::distinct expected size <= upper"); + + return distinct(size, T(0), upper - 1); + } + + /* Returns random (unsorted) partition which is a representation of sum as a sum of integers not less than min_part. */ + template + std::vector partition(int size, T sum, T min_part) { + if (size < 0) + __testlib_fail("random_t::partition: size < 0"); + if (size == 0 && sum != 0) + __testlib_fail("random_t::partition: size == 0 && sum != 0"); + if (min_part * size > sum) + __testlib_fail("random_t::partition: min_part * size > sum"); + if (size == 0 && sum == 0) + return std::vector(); + + T sum_ = sum; + sum -= min_part * size; + + std::vector septums(size); + std::vector d = distinct(size - 1, T(1), T(sum + size - 1)); + for (int i = 0; i + 1 < size; i++) + septums[i + 1] = d[i]; + sort(septums.begin(), septums.end()); + + std::vector result(size); + for (int i = 0; i + 1 < size; i++) + result[i] = septums[i + 1] - septums[i] - 1; + result[size - 1] = sum + size - 1 - septums.back(); + + for (std::size_t i = 0; i < result.size(); i++) + result[i] += min_part; + + T result_sum = 0; + for (std::size_t i = 0; i < result.size(); i++) + result_sum += result[i]; + if (result_sum != sum_) + __testlib_fail("random_t::partition: partition sum is expected to be the given sum"); + + if (*std::min_element(result.begin(), result.end()) < min_part) + __testlib_fail("random_t::partition: partition min is expected to be no less than the given min_part"); + + if (int(result.size()) != size || result.size() != (size_t) size) + __testlib_fail("random_t::partition: partition size is expected to be equal to the given size"); + + return result; + } + + /* Returns random (unsorted) partition which is a representation of sum as a sum of positive integers. */ + template + std::vector partition(int size, T sum) { + return partition(size, sum, T(1)); + } +}; + +const int random_t::lim = 25; +const unsigned long long random_t::multiplier = 0x5DEECE66DLL; +const unsigned long long random_t::addend = 0xBLL; +const unsigned long long random_t::mask = (1LL << 48) - 1; +int random_t::version = -1; + +/* Pattern implementation */ +bool pattern::matches(const std::string &s) const { + return matches(s, 0); +} + +static bool __pattern_isSlash(const std::string &s, size_t pos) { + return s[pos] == '\\'; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static bool __pattern_isCommandChar(const std::string &s, size_t pos, char value) { + if (pos >= s.length()) + return false; + + int slashes = 0; + + int before = int(pos) - 1; + while (before >= 0 && s[before] == '\\') + before--, slashes++; + + return slashes % 2 == 0 && s[pos] == value; +} + +static char __pattern_getChar(const std::string &s, size_t &pos) { + if (__pattern_isSlash(s, pos)) + pos += 2; + else + pos++; + + return s[pos - 1]; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static int __pattern_greedyMatch(const std::string &s, size_t pos, const std::vector chars) { + int result = 0; + + while (pos < s.length()) { + char c = s[pos++]; + if (!std::binary_search(chars.begin(), chars.end(), c)) + break; + else + result++; + } + + return result; +} + +std::string pattern::src() const { + return s; +} + +bool pattern::matches(const std::string &s, size_t pos) const { + std::string result; + + if (to > 0) { + int size = __pattern_greedyMatch(s, pos, chars); + if (size < from) + return false; + if (size > to) + size = to; + pos += size; + } + + if (children.size() > 0) { + for (size_t child = 0; child < children.size(); child++) + if (children[child].matches(s, pos)) + return true; + return false; + } else + return pos == s.length(); +} + +std::string pattern::next(random_t &rnd) const { + std::string result; + result.reserve(20); + + if (to == INT_MAX) + __testlib_fail("pattern::next(random_t& rnd): can't process character '*' for generation"); + + if (to > 0) { + int count = rnd.next(to - from + 1) + from; + for (int i = 0; i < count; i++) + result += chars[rnd.next(int(chars.size()))]; + } + + if (children.size() > 0) { + int child = rnd.next(int(children.size())); + result += children[child].next(rnd); + } + + return result; +} + +static void __pattern_scanCounts(const std::string &s, size_t &pos, int &from, int &to) { + if (pos >= s.length()) { + from = to = 1; + return; + } + + if (__pattern_isCommandChar(s, pos, '{')) { + std::vector parts; + std::string part; + + pos++; + + while (pos < s.length() && !__pattern_isCommandChar(s, pos, '}')) { + if (__pattern_isCommandChar(s, pos, ',')) + parts.push_back(part), part = "", pos++; + else + part += __pattern_getChar(s, pos); + } + + if (part != "") + parts.push_back(part); + + if (!__pattern_isCommandChar(s, pos, '}')) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + pos++; + + if (parts.size() < 1 || parts.size() > 2) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + std::vector numbers; + + for (size_t i = 0; i < parts.size(); i++) { + if (parts[i].length() == 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + int number; + if (std::sscanf(parts[i].c_str(), "%d", &number) != 1) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + numbers.push_back(number); + } + + if (numbers.size() == 1) + from = to = numbers[0]; + else + from = numbers[0], to = numbers[1]; + + if (from > to) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + } else { + if (__pattern_isCommandChar(s, pos, '?')) { + from = 0, to = 1, pos++; + return; + } + + if (__pattern_isCommandChar(s, pos, '*')) { + from = 0, to = INT_MAX, pos++; + return; + } + + if (__pattern_isCommandChar(s, pos, '+')) { + from = 1, to = INT_MAX, pos++; + return; + } + + from = to = 1; + } +} + +static std::vector __pattern_scanCharSet(const std::string &s, size_t &pos) { + if (pos >= s.length()) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + std::vector result; + + if (__pattern_isCommandChar(s, pos, '[')) { + pos++; + bool negative = __pattern_isCommandChar(s, pos, '^'); + if (negative) + pos++; + + char prev = 0; + + while (pos < s.length() && !__pattern_isCommandChar(s, pos, ']')) { + if (__pattern_isCommandChar(s, pos, '-') && prev != 0) { + pos++; + + if (pos + 1 == s.length() || __pattern_isCommandChar(s, pos, ']')) { + result.push_back(prev); + prev = '-'; + continue; + } + + char next = __pattern_getChar(s, pos); + if (prev > next) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + for (char c = prev; c != next; c++) + result.push_back(c); + result.push_back(next); + + prev = 0; + } else { + if (prev != 0) + result.push_back(prev); + prev = __pattern_getChar(s, pos); + } + } + + if (prev != 0) + result.push_back(prev); + + if (!__pattern_isCommandChar(s, pos, ']')) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + pos++; + + if (negative) { + std::sort(result.begin(), result.end()); + std::vector actuals; + for (int code = 0; code < 255; code++) { + char c = char(code); + if (!std::binary_search(result.begin(), result.end(), c)) + actuals.push_back(c); + } + result = actuals; + } + + std::sort(result.begin(), result.end()); + } else + result.push_back(__pattern_getChar(s, pos)); + + return result; +} + +pattern::pattern(std::string s) : s(s), from(0), to(0) { + std::string t; + for (size_t i = 0; i < s.length(); i++) + if (!__pattern_isCommandChar(s, i, ' ')) + t += s[i]; + s = t; + + int opened = 0; + int firstClose = -1; + std::vector seps; + + for (size_t i = 0; i < s.length(); i++) { + if (__pattern_isCommandChar(s, i, '(')) { + opened++; + continue; + } + + if (__pattern_isCommandChar(s, i, ')')) { + opened--; + if (opened == 0 && firstClose == -1) + firstClose = int(i); + continue; + } + + if (opened < 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + if (__pattern_isCommandChar(s, i, '|') && opened == 0) + seps.push_back(int(i)); + } + + if (opened != 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + if (seps.size() == 0 && firstClose + 1 == (int) s.length() + && __pattern_isCommandChar(s, 0, '(') && __pattern_isCommandChar(s, s.length() - 1, ')')) { + children.push_back(pattern(s.substr(1, s.length() - 2))); + } else { + if (seps.size() > 0) { + seps.push_back(int(s.length())); + int last = 0; + + for (size_t i = 0; i < seps.size(); i++) { + children.push_back(pattern(s.substr(last, seps[i] - last))); + last = seps[i] + 1; + } + } else { + size_t pos = 0; + chars = __pattern_scanCharSet(s, pos); + __pattern_scanCounts(s, pos, from, to); + if (pos < s.length()) + children.push_back(pattern(s.substr(pos))); + } + } +} + +/* End of pattern implementation */ + +template +inline bool isEof(C c) { + return c == EOFC; +} + +template +inline bool isEoln(C c) { + return (c == LF || c == CR); +} + +template +inline bool isBlanks(C c) { + return (c == LF || c == CR || c == SPACE || c == TAB); +} + +inline std::string trim(const std::string &s) { + if (s.empty()) + return s; + + int left = 0; + while (left < int(s.length()) && isBlanks(s[left])) + left++; + if (left >= int(s.length())) + return ""; + + int right = int(s.length()) - 1; + while (right >= 0 && isBlanks(s[right])) + right--; + if (right < 0) + return ""; + + return s.substr(left, right - left + 1); +} + +enum TMode { + _input, _output, _answer +}; + +/* Outcomes 6-15 are reserved for future use. */ +enum TResult { + _ok = 0, + _wa = 1, + _pe = 2, + _fail = 3, + _dirt = 4, + _points = 5, + _unexpected_eof = 8, + _partially = 16 +}; + +enum TTestlibMode { + _unknown, _checker, _validator, _generator, _interactor, _scorer +}; + +#define _pc(exitCode) (TResult(_partially + (exitCode))) + +/* Outcomes 6-15 are reserved for future use. */ +const std::string outcomes[] = { + "accepted", + "wrong-answer", + "presentation-error", + "fail", + "fail", +#ifndef PCMS2 + "points", +#else + "relative-scoring", +#endif + "reserved", + "reserved", + "unexpected-eof", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "partially-correct" +}; + +class InputStreamReader { +public: + virtual void setTestCase(int testCase) = 0; + + virtual std::vector getReadChars() = 0; + + virtual int curChar() = 0; + + virtual int nextChar() = 0; + + virtual void skipChar() = 0; + + virtual void unreadChar(int c) = 0; + + virtual std::string getName() = 0; + + virtual bool eof() = 0; + + virtual void close() = 0; + + virtual int getLine() = 0; + + virtual ~InputStreamReader() = 0; +}; + +InputStreamReader::~InputStreamReader() { + // No operations. +} + +class StringInputStreamReader : public InputStreamReader { +private: + std::string s; + size_t pos; + +public: + StringInputStreamReader(const std::string &content) : s(content), pos(0) { + // No operations. + } + + void setTestCase(int) { + __testlib_fail("setTestCase not implemented in StringInputStreamReader"); + } + + std::vector getReadChars() { + __testlib_fail("getReadChars not implemented in StringInputStreamReader"); + } + + int curChar() { + if (pos >= s.length()) + return EOFC; + else + return s[pos]; + } + + int nextChar() { + if (pos >= s.length()) { + pos++; + return EOFC; + } else + return s[pos++]; + } + + void skipChar() { + pos++; + } + + void unreadChar(int c) { + if (pos == 0) + __testlib_fail("StringInputStreamReader::unreadChar(int): pos == 0."); + pos--; + if (pos < s.length()) + s[pos] = char(c); + } + + std::string getName() { + return __testlib_part(s); + } + + int getLine() { + return -1; + } + + bool eof() { + return pos >= s.length(); + } + + void close() { + // No operations. + } +}; + +class FileInputStreamReader : public InputStreamReader { +private: + std::FILE *file; + std::string name; + int line; + std::vector undoChars; + std::vector readChars; + std::vector undoReadChars; + + inline int postprocessGetc(int getcResult) { + if (getcResult != EOF) + return getcResult; + else + return EOFC; + } + + int getc(FILE *file) { + int c; + int rc; + + if (undoChars.empty()) { + c = rc = ::getc(file); + } else { + c = undoChars.back(); + undoChars.pop_back(); + rc = undoReadChars.back(); + undoReadChars.pop_back(); + } + + if (c == LF) + line++; + + readChars.push_back(rc); + return c; + } + + int ungetc(int c/*, FILE* file*/) { + if (!readChars.empty()) { + undoReadChars.push_back(readChars.back()); + readChars.pop_back(); + } + if (c == LF) + line--; + undoChars.push_back(c); + return c; + } + +public: + FileInputStreamReader(std::FILE *file, const std::string &name) : file(file), name(name), line(1) { + // No operations. + } + + void setTestCase(int testCase) { + if (testCase < 0 || testCase > __TESTLIB_MAX_TEST_CASE) + __testlib_fail(format("testCase expected fit in [1,%d], but %d doesn't", __TESTLIB_MAX_TEST_CASE, testCase)); + readChars.push_back(testCase + 256); + } + + std::vector getReadChars() { + return readChars; + } + + int curChar() { + if (feof(file)) + return EOFC; + else { + int c = getc(file); + ungetc(c/*, file*/); + return postprocessGetc(c); + } + } + + int nextChar() { + if (feof(file)) + return EOFC; + else + return postprocessGetc(getc(file)); + } + + void skipChar() { + getc(file); + } + + void unreadChar(int c) { + ungetc(c/*, file*/); + } + + std::string getName() { + return name; + } + + int getLine() { + return line; + } + + bool eof() { + if (NULL == file || feof(file)) + return true; + else { + int c = nextChar(); + if (c == EOFC || (c == EOF && feof(file))) + return true; + unreadChar(c); + return false; + } + } + + void close() { + if (NULL != file) { + fclose(file); + file = NULL; + } + } +}; + +class BufferedFileInputStreamReader : public InputStreamReader { +private: + static const size_t BUFFER_SIZE; + static const size_t MAX_UNREAD_COUNT; + + std::FILE *file; + std::string name; + int line; + + char *buffer; + bool *isEof; + int bufferPos; + size_t bufferSize; + + bool refill() { + if (NULL == file) + __testlib_fail("BufferedFileInputStreamReader: file == NULL (" + getName() + ")"); + + if (bufferPos >= int(bufferSize)) { + size_t readSize = fread( + buffer + MAX_UNREAD_COUNT, + 1, + BUFFER_SIZE - MAX_UNREAD_COUNT, + file + ); + + if (readSize < BUFFER_SIZE - MAX_UNREAD_COUNT + && ferror(file)) + __testlib_fail("BufferedFileInputStreamReader: unable to read (" + getName() + ")"); + + bufferSize = MAX_UNREAD_COUNT + readSize; + bufferPos = int(MAX_UNREAD_COUNT); + std::memset(isEof + MAX_UNREAD_COUNT, 0, sizeof(isEof[0]) * readSize); + + return readSize > 0; + } else + return true; + } + + char increment() { + char c; + if ((c = buffer[bufferPos++]) == LF) + line++; + return c; + } + +public: + BufferedFileInputStreamReader(std::FILE *file, const std::string &name) : file(file), name(name), line(1) { + buffer = new char[BUFFER_SIZE]; + isEof = new bool[BUFFER_SIZE]; + bufferSize = MAX_UNREAD_COUNT; + bufferPos = int(MAX_UNREAD_COUNT); + } + + ~BufferedFileInputStreamReader() { + if (NULL != buffer) { + delete[] buffer; + buffer = NULL; + } + if (NULL != isEof) { + delete[] isEof; + isEof = NULL; + } + } + + void setTestCase(int) { + __testlib_fail("setTestCase not implemented in BufferedFileInputStreamReader"); + } + + std::vector getReadChars() { + __testlib_fail("getReadChars not implemented in BufferedFileInputStreamReader"); + } + + int curChar() { + if (!refill()) + return EOFC; + + return isEof[bufferPos] ? EOFC : buffer[bufferPos]; + } + + int nextChar() { + if (!refill()) + return EOFC; + + return isEof[bufferPos] ? EOFC : increment(); + } + + void skipChar() { + increment(); + } + + void unreadChar(int c) { + bufferPos--; + if (bufferPos < 0) + __testlib_fail("BufferedFileInputStreamReader::unreadChar(int): bufferPos < 0"); + isEof[bufferPos] = (c == EOFC); + buffer[bufferPos] = char(c); + if (c == LF) + line--; + } + + std::string getName() { + return name; + } + + int getLine() { + return line; + } + + bool eof() { + return !refill() || EOFC == curChar(); + } + + void close() { + if (NULL != file) { + fclose(file); + file = NULL; + } + } +}; + +const size_t BufferedFileInputStreamReader::BUFFER_SIZE = 2000000; +const size_t BufferedFileInputStreamReader::MAX_UNREAD_COUNT = BufferedFileInputStreamReader::BUFFER_SIZE / 2; + +/* + * Streams to be used for reading data in checkers or validators. + * Each read*() method moves pointer to the next character after the + * read value. + */ +struct InStream { + /* Do not use them. */ + InStream(); + + ~InStream(); + + /* Wrap std::string with InStream. */ + InStream(const InStream &baseStream, std::string content); + + InputStreamReader *reader; + int lastLine; + + std::string name; + TMode mode; + bool opened; + bool stdfile; + bool strict; + + int wordReserveSize; + std::string _tmpReadToken; + + int readManyIteration; + size_t maxFileSize; + size_t maxTokenLength; + size_t maxMessageLength; + + void init(std::string fileName, TMode mode); + + void init(std::FILE *f, TMode mode); + + void setTestCase(int testCase); + std::vector getReadChars(); + + /* Moves stream pointer to the first non-white-space character or EOF. */ + void skipBlanks(); + + /* Returns current character in the stream. Doesn't remove it from stream. */ + char curChar(); + + /* Moves stream pointer one character forward. */ + void skipChar(); + + /* Returns current character and moves pointer one character forward. */ + char nextChar(); + + /* Returns current character and moves pointer one character forward. */ + char readChar(); + + /* As "readChar()" but ensures that the result is equal to given parameter. */ + char readChar(char c); + + /* As "readChar()" but ensures that the result is equal to the space (code=32). */ + char readSpace(); + + /* Puts back the character into the stream. */ + void unreadChar(char c); + + /* Reopens stream, you should not use it. */ + void reset(std::FILE *file = NULL); + + /* Checks that current position is EOF. If not it doesn't move stream pointer. */ + bool eof(); + + /* Moves pointer to the first non-white-space character and calls "eof()". */ + bool seekEof(); + + /* + * Checks that current position contains EOLN. + * If not it doesn't move stream pointer. + * In strict mode expects "#13#10" for windows or "#10" for other platforms. + */ + bool eoln(); + + /* Moves pointer to the first non-space and non-tab character and calls "eoln()". */ + bool seekEoln(); + + /* Moves stream pointer to the first character of the next line (if exists). */ + void nextLine(); + + /* + * Reads new token. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + std::string readWord(); + + /* The same as "readWord()", it is preffered to use "readToken()". */ + std::string readToken(); + + /* The same as "readWord()", but ensures that token matches to given pattern. */ + std::string readWord(const std::string &ptrn, const std::string &variableName = ""); + + std::string readWord(const pattern &p, const std::string &variableName = ""); + + std::vector + readWords(int size, const std::string &ptrn, const std::string &variablesName = "", int indexBase = 1); + + std::vector + readWords(int size, const pattern &p, const std::string &variablesName = "", int indexBase = 1); + + std::vector readWords(int size, int indexBase = 1); + + /* The same as "readToken()", but ensures that token matches to given pattern. */ + std::string readToken(const std::string &ptrn, const std::string &variableName = ""); + + std::string readToken(const pattern &p, const std::string &variableName = ""); + + std::vector + readTokens(int size, const std::string &ptrn, const std::string &variablesName = "", int indexBase = 1); + + std::vector + readTokens(int size, const pattern &p, const std::string &variablesName = "", int indexBase = 1); + + std::vector readTokens(int size, int indexBase = 1); + + void readWordTo(std::string &result); + + void readWordTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + void readWordTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + void readTokenTo(std::string &result); + + void readTokenTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + void readTokenTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* + * Reads new long long value. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + long long readLong(); + + unsigned long long readUnsignedLong(); + + /* + * Reads new int. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + int readInteger(); + + /* + * Reads new int. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + int readInt(); + + /* As "readLong()" but ensures that value in the range [minv,maxv]. */ + long long readLong(long long minv, long long maxv, const std::string &variableName = ""); + + /* Reads space-separated sequence of long longs. */ + std::vector + readLongs(int size, long long minv, long long maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of long longs. */ + std::vector readLongs(int size, int indexBase = 1); + + unsigned long long + readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName = ""); + + std::vector + readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string &variablesName = "", + int indexBase = 1); + + std::vector readUnsignedLongs(int size, int indexBase = 1); + + unsigned long long readLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName = ""); + + std::vector + readLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string &variablesName = "", + int indexBase = 1); + + /* As "readInteger()" but ensures that value in the range [minv,maxv]. */ + int readInteger(int minv, int maxv, const std::string &variableName = ""); + + /* As "readInt()" but ensures that value in the range [minv,maxv]. */ + int readInt(int minv, int maxv, const std::string &variableName = ""); + + /* Reads space-separated sequence of integers. */ + std::vector + readIntegers(int size, int minv, int maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readIntegers(int size, int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readInts(int size, int minv, int maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readInts(int size, int indexBase = 1); + + /* + * Reads new double. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + double readReal(); + + /* + * Reads new double. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + double readDouble(); + + /* As "readReal()" but ensures that value in the range [minv,maxv]. */ + double readReal(double minv, double maxv, const std::string &variableName = ""); + + std::vector + readReals(int size, double minv, double maxv, const std::string &variablesName = "", int indexBase = 1); + + std::vector readReals(int size, int indexBase = 1); + + /* As "readDouble()" but ensures that value in the range [minv,maxv]. */ + double readDouble(double minv, double maxv, const std::string &variableName = ""); + + std::vector + readDoubles(int size, double minv, double maxv, const std::string &variablesName = "", int indexBase = 1); + + std::vector readDoubles(int size, int indexBase = 1); + + /* + * As "readReal()" but ensures that value in the range [minv,maxv] and + * number of digit after the decimal point is in range [minAfterPointDigitCount,maxAfterPointDigitCount] + * and number is in the form "[-]digit(s)[.digit(s)]". + */ + double readStrictReal(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName = ""); + + std::vector readStrictReals(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName = "", int indexBase = 1); + + /* + * As "readDouble()" but ensures that value in the range [minv,maxv] and + * number of digit after the decimal point is in range [minAfterPointDigitCount,maxAfterPointDigitCount] + * and number is in the form "[-]digit(s)[.digit(s)]". + */ + double readStrictDouble(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName = ""); + + std::vector readStrictDoubles(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName = "", int indexBase = 1); + + /* As readLine(). */ + std::string readString(); + + /* Read many lines. */ + std::vector readStrings(int size, int indexBase = 1); + + /* See readLine(). */ + void readStringTo(std::string &result); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + std::string readString(const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + std::string readString(const std::string &ptrn, const std::string &variableName = ""); + + /* Read many lines. */ + std::vector + readStrings(int size, const pattern &p, const std::string &variableName = "", int indexBase = 1); + + /* Read many lines. */ + std::vector + readStrings(int size, const std::string &ptrn, const std::string &variableName = "", int indexBase = 1); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + void readStringTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + void readStringTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* + * Reads line from the current position to EOLN or EOF. Moves stream pointer to + * the first character of the new line (if possible). + */ + std::string readLine(); + + /* Read many lines. */ + std::vector readLines(int size, int indexBase = 1); + + /* See readLine(). */ + void readLineTo(std::string &result); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + std::string readLine(const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + std::string readLine(const std::string &ptrn, const std::string &variableName = ""); + + /* Read many lines. */ + std::vector + readLines(int size, const pattern &p, const std::string &variableName = "", int indexBase = 1); + + /* Read many lines. */ + std::vector + readLines(int size, const std::string &ptrn, const std::string &variableName = "", int indexBase = 1); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + void readLineTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + void readLineTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* Reads EOLN or fails. Use it in validators. Calls "eoln()" method internally. */ + void readEoln(); + + /* Reads EOF or fails. Use it in validators. Calls "eof()" method internally. */ + void readEof(); + + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quit(TResult result, const char *msg); + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quitf(TResult result, const char *msg, ...); + + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + void quitif(bool condition, TResult result, const char *msg, ...); + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quits(TResult result, std::string msg); + + /* + * Checks condition and aborts a program if codition is false. + * Returns _wa for ouf and _fail on any other streams. + */ +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif + void ensuref(bool cond, const char *format, ...); + + void __testlib_ensure(bool cond, std::string message); + + void close(); + + const static int NO_INDEX = INT_MAX; + const static char OPEN_BRACKET = char(11); + const static char CLOSE_BRACKET = char(17); + + const static WORD LightGray = 0x07; + const static WORD LightRed = 0x0c; + const static WORD LightCyan = 0x0b; + const static WORD LightGreen = 0x0a; + const static WORD LightYellow = 0x0e; + + static void textColor(WORD color); + + static void quitscr(WORD color, const char *msg); + + static void quitscrS(WORD color, std::string msg); + + void xmlSafeWrite(std::FILE *file, const char *msg); + + /* Skips UTF-8 Byte Order Mark. */ + void skipBom(); + +private: + InStream(const InStream &); + + InStream &operator=(const InStream &); +}; + +InStream inf; +InStream ouf; +InStream ans; +bool appesMode; +std::string resultName; +std::string checkerName = "untitled checker"; +random_t rnd; +TTestlibMode testlibMode = _unknown; +double __testlib_points = std::numeric_limits::infinity(); + +struct ValidatorBoundsHit { + static const double EPS; + bool minHit; + bool maxHit; + + ValidatorBoundsHit(bool minHit = false, bool maxHit = false) : minHit(minHit), maxHit(maxHit) { + }; + + ValidatorBoundsHit merge(const ValidatorBoundsHit &validatorBoundsHit) { + return ValidatorBoundsHit( + __testlib_max(minHit, validatorBoundsHit.minHit), + __testlib_max(maxHit, validatorBoundsHit.maxHit) + ); + } +}; + +const double ValidatorBoundsHit::EPS = 1E-12; + +class Validator { +private: + const static std::string TEST_MARKUP_HEADER; + const static std::string TEST_CASE_OPEN_TAG; + const static std::string TEST_CASE_CLOSE_TAG; + + bool _initialized; + std::string _testset; + std::string _group; + + std::string _testOverviewLogFileName; + std::string _testMarkupFileName; + int _testCase = -1; + std::string _testCaseFileName; + + std::map _boundsHitByVariableName; + std::set _features; + std::set _hitFeatures; + + bool isVariableNameBoundsAnalyzable(const std::string &variableName) { + for (size_t i = 0; i < variableName.length(); i++) + if ((variableName[i] >= '0' && variableName[i] <= '9') || variableName[i] < ' ') + return false; + return true; + } + + bool isFeatureNameAnalyzable(const std::string &featureName) { + for (size_t i = 0; i < featureName.length(); i++) + if (featureName[i] < ' ') + return false; + return true; + } + +public: + Validator() : _initialized(false), _testset("tests"), _group() { + } + + void initialize() { + _initialized = true; + } + + std::string testset() const { + if (!_initialized) + __testlib_fail("Validator should be initialized with registerValidation(argc, argv) instead of registerValidation() to support validator.testset()"); + return _testset; + } + + std::string group() const { + if (!_initialized) + __testlib_fail("Validator should be initialized with registerValidation(argc, argv) instead of registerValidation() to support validator.group()"); + return _group; + } + + std::string testOverviewLogFileName() const { + return _testOverviewLogFileName; + } + + std::string testMarkupFileName() const { + return _testMarkupFileName; + } + + int testCase() const { + return _testCase; + } + + std::string testCaseFileName() const { + return _testCaseFileName; + } + + void setTestset(const char *const testset) { + _testset = testset; + } + + void setGroup(const char *const group) { + _group = group; + } + + void setTestOverviewLogFileName(const char *const testOverviewLogFileName) { + _testOverviewLogFileName = testOverviewLogFileName; + } + + void setTestMarkupFileName(const char *const testMarkupFileName) { + _testMarkupFileName = testMarkupFileName; + } + + void setTestCase(int testCase) { + _testCase = testCase; + } + + void setTestCaseFileName(const char *const testCaseFileName) { + _testCaseFileName = testCaseFileName; + } + + void addBoundsHit(const std::string &variableName, ValidatorBoundsHit boundsHit) { + if (isVariableNameBoundsAnalyzable(variableName)) { + _boundsHitByVariableName[variableName] + = boundsHit.merge(_boundsHitByVariableName[variableName]); + } + } + + std::string getBoundsHitLog() { + std::string result; + for (std::map::iterator i = _boundsHitByVariableName.begin(); + i != _boundsHitByVariableName.end(); + i++) { + result += "\"" + i->first + "\":"; + if (i->second.minHit) + result += " min-value-hit"; + if (i->second.maxHit) + result += " max-value-hit"; + result += "\n"; + } + return result; + } + + std::string getFeaturesLog() { + std::string result; + for (std::set::iterator i = _features.begin(); + i != _features.end(); + i++) { + result += "feature \"" + *i + "\":"; + if (_hitFeatures.count(*i)) + result += " hit"; + result += "\n"; + } + return result; + } + + void writeTestOverviewLog() { + if (!_testOverviewLogFileName.empty()) { + std::string fileName(_testOverviewLogFileName); + _testOverviewLogFileName = ""; + FILE *testOverviewLogFile = fopen(fileName.c_str(), "w"); + if (NULL == testOverviewLogFile) + __testlib_fail("Validator::writeTestOverviewLog: can't write test overview log to (" + fileName + ")"); + fprintf(testOverviewLogFile, "%s%s", getBoundsHitLog().c_str(), getFeaturesLog().c_str()); + if (fclose(testOverviewLogFile)) + __testlib_fail( + "Validator::writeTestOverviewLog: can't close test overview log file (" + fileName + ")"); + } + } + + void writeTestMarkup() { + if (!_testMarkupFileName.empty()) { + std::vector readChars = inf.getReadChars(); + if (!readChars.empty()) { + std::string markup(TEST_MARKUP_HEADER); + for (size_t i = 0; i < readChars.size(); i++) { + int c = readChars[i]; + if (i + 1 == readChars.size() && c == -1) + continue; + if (c <= 256) { + char cc = char(c); + if (cc == '\\' || cc == '!') + markup += '\\'; + markup += cc; + } else { + markup += TEST_CASE_OPEN_TAG; + markup += toString(c - 256); + markup += TEST_CASE_CLOSE_TAG; + } + } + FILE* f; + bool standard_file = false; + if (_testMarkupFileName == "stdout") + f = stdout, standard_file = true; + else if (_testMarkupFileName == "stderr") + f = stderr, standard_file = true; + else { + f = fopen(_testMarkupFileName.c_str(), "wb"); + if (NULL == f) + __testlib_fail("Validator::writeTestMarkup: can't write test markup to (" + _testMarkupFileName + ")"); + } + std::fprintf(f, "%s", markup.c_str()); + std::fflush(f); + if (!standard_file) + if (std::fclose(f)) + __testlib_fail("Validator::writeTestMarkup: can't close test markup file (" + _testCaseFileName + ")"); + } + } + } + + void writeTestCase() { + if (_testCase > 0) { + std::vector readChars = inf.getReadChars(); + if (!readChars.empty()) { + std::string content, testCaseContent; + bool matchedTestCase = false; + for (size_t i = 0; i < readChars.size(); i++) { + int c = readChars[i]; + if (i + 1 == readChars.size() && c == -1) + continue; + if (c <= 256) + content += char(c); + else { + if (matchedTestCase) { + testCaseContent = content; + matchedTestCase = false; + } + content = ""; + int testCase = c - 256; + if (testCase == _testCase) + matchedTestCase = true; + } + } + if (matchedTestCase) + testCaseContent = content; + + if (!testCaseContent.empty()) { + FILE* f; + bool standard_file = false; + if (_testCaseFileName.empty() || _testCaseFileName == "stdout") + f = stdout, standard_file = true; + else if (_testCaseFileName == "stderr") + f = stderr, standard_file = true; + else { + f = fopen(_testCaseFileName.c_str(), "wb"); + if (NULL == f) + __testlib_fail("Validator::writeTestCase: can't write test case to (" + _testCaseFileName + ")"); + } + std::fprintf(f, "%s", testCaseContent.c_str()); + std::fflush(f); + if (!standard_file) + if (std::fclose(f)) + __testlib_fail("Validator::writeTestCase: can't close test case file (" + _testCaseFileName + ")"); + } + } + } + } + + void addFeature(const std::string &feature) { + if (_features.count(feature)) + __testlib_fail("Feature " + feature + " registered twice."); + if (!isFeatureNameAnalyzable(feature)) + __testlib_fail("Feature name '" + feature + "' contains restricted characters."); + + _features.insert(feature); + } + + void feature(const std::string &feature) { + if (!isFeatureNameAnalyzable(feature)) + __testlib_fail("Feature name '" + feature + "' contains restricted characters."); + + if (!_features.count(feature)) + __testlib_fail("Feature " + feature + " didn't registered via addFeature(feature)."); + + _hitFeatures.insert(feature); + } +} validator; + +const std::string Validator::TEST_MARKUP_HEADER = "MU\xF3\x01"; +const std::string Validator::TEST_CASE_OPEN_TAG = "!c"; +const std::string Validator::TEST_CASE_CLOSE_TAG = ";"; + +struct TestlibFinalizeGuard { + static bool alive; + static bool registered; + + int quitCount, readEofCount; + + TestlibFinalizeGuard() : quitCount(0), readEofCount(0) { + // No operations. + } + + ~TestlibFinalizeGuard() { + bool _alive = alive; + alive = false; + + if (_alive) { + if (testlibMode == _checker && quitCount == 0) + __testlib_fail("Checker must end with quit or quitf call."); + + if (testlibMode == _validator && readEofCount == 0 && quitCount == 0) + __testlib_fail("Validator must end with readEof call."); + + /* opts */ + autoEnsureNoUnusedOpts(); + + if (!registered) + __testlib_fail("Call register-function in the first line of the main (registerTestlibCmd or other similar)"); + } + + if (__testlib_exitCode == 0) { + validator.writeTestOverviewLog(); + validator.writeTestMarkup(); + validator.writeTestCase(); + } + } + +private: + /* opts */ + void autoEnsureNoUnusedOpts(); +}; + +bool TestlibFinalizeGuard::alive = true; +bool TestlibFinalizeGuard::registered = false; +extern TestlibFinalizeGuard testlibFinalizeGuard; + +/* + * Call it to disable checks on finalization. + */ +void disableFinalizeGuard() { + TestlibFinalizeGuard::alive = false; +} + +/* Interactor streams. + */ +std::fstream tout; + +/* implementation + */ + +InStream::InStream() { + reader = NULL; + lastLine = -1; + opened = false; + name = ""; + mode = _input; + strict = false; + stdfile = false; + wordReserveSize = 4; + readManyIteration = NO_INDEX; + maxFileSize = 128 * 1024 * 1024; // 128MB. + maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxMessageLength = 32000; +} + +InStream::InStream(const InStream &baseStream, std::string content) { + reader = new StringInputStreamReader(content); + lastLine = -1; + opened = true; + strict = baseStream.strict; + stdfile = false; + mode = baseStream.mode; + name = "based on " + baseStream.name; + readManyIteration = NO_INDEX; + maxFileSize = 128 * 1024 * 1024; // 128MB. + maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxMessageLength = 32000; +} + +InStream::~InStream() { + if (NULL != reader) { + reader->close(); + delete reader; + reader = NULL; + } +} + +void InStream::setTestCase(int testCase) { + if (testlibMode != _validator || mode != _input || !stdfile || this != &inf) + __testlib_fail("InStream::setTestCase can be used only for inf in validator-mode." + " Actually, prefer setTestCase function instead of InStream member"); + reader->setTestCase(testCase); +} + +std::vector InStream::getReadChars() { + if (testlibMode != _validator || mode != _input || !stdfile || this != &inf) + __testlib_fail("InStream::getReadChars can be used only for inf in validator-mode."); + return reader == NULL ? std::vector() : reader->getReadChars(); +} + +void setTestCase(int testCase) { + static bool first_run = true; + static bool zero_based = false; + + if (first_run && testCase == 0) + zero_based = true; + + if (zero_based) + testCase++; + + __testlib_hasTestCase = true; + __testlib_testCase = testCase; + + if (testlibMode == _validator) + inf.setTestCase(testCase); + + first_run = false; +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +int resultExitCode(TResult r) { + if (r == _ok) + return OK_EXIT_CODE; + if (r == _wa) + return WA_EXIT_CODE; + if (r == _pe) + return PE_EXIT_CODE; + if (r == _fail) + return FAIL_EXIT_CODE; + if (r == _dirt) + return DIRT_EXIT_CODE; + if (r == _points) + return POINTS_EXIT_CODE; + if (r == _unexpected_eof) +#ifdef ENABLE_UNEXPECTED_EOF + return UNEXPECTED_EOF_EXIT_CODE; +#else + return PE_EXIT_CODE; +#endif + if (r >= _partially) + return PC_BASE_EXIT_CODE + (r - _partially); + return FAIL_EXIT_CODE; +} + +void InStream::textColor( +#if !(defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400)) && defined(__GNUC__) + __attribute__((unused)) +#endif + WORD color +) { +#if defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400) + HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleTextAttribute(handle, color); +#endif +#if !defined(ON_WINDOWS) && defined(__GNUC__) + if (isatty(2)) + { + switch (color) + { + case LightRed: + fprintf(stderr, "\033[1;31m"); + break; + case LightCyan: + fprintf(stderr, "\033[1;36m"); + break; + case LightGreen: + fprintf(stderr, "\033[1;32m"); + break; + case LightYellow: + fprintf(stderr, "\033[1;33m"); + break; + case LightGray: + default: + fprintf(stderr, "\033[0m"); + } + } +#endif +} + +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT +class exit_exception: public std::exception { +private: + int exitCode; +public: + exit_exception(int exitCode): exitCode(exitCode) {} + int getExitCode() { return exitCode; } +}; +#endif + +NORETURN void halt(int exitCode) { +#ifdef FOOTER + InStream::textColor(InStream::LightGray); + std::fprintf(stderr, "Checker: \"%s\"\n", checkerName.c_str()); + std::fprintf(stderr, "Exit code: %d\n", exitCode); + InStream::textColor(InStream::LightGray); +#endif + __testlib_exitCode = exitCode; +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT + throw exit_exception(exitCode); +#endif + std::exit(exitCode); +} + +static bool __testlib_shouldCheckDirt(TResult result) { + return result == _ok || result == _points || result >= _partially; +} + +static std::string __testlib_appendMessage(const std::string &message, const std::string &extra) { + int openPos = -1, closePos = -1; + for (size_t i = 0; i < message.length(); i++) { + if (message[i] == InStream::OPEN_BRACKET) { + if (openPos == -1) + openPos = int(i); + else + openPos = INT_MAX; + } + if (message[i] == InStream::CLOSE_BRACKET) { + if (closePos == -1) + closePos = int(i); + else + closePos = INT_MAX; + } + } + if (openPos != -1 && openPos != INT_MAX + && closePos != -1 && closePos != INT_MAX + && openPos < closePos) { + size_t index = message.find(extra, openPos); + if (index == std::string::npos || int(index) >= closePos) { + std::string result(message); + result.insert(closePos, ", " + extra); + return result; + } + return message; + } + + return message + " " + InStream::OPEN_BRACKET + extra + InStream::CLOSE_BRACKET; +} + +static std::string __testlib_toPrintableMessage(const std::string &message) { + int openPos = -1, closePos = -1; + for (size_t i = 0; i < message.length(); i++) { + if (message[i] == InStream::OPEN_BRACKET) { + if (openPos == -1) + openPos = int(i); + else + openPos = INT_MAX; + } + if (message[i] == InStream::CLOSE_BRACKET) { + if (closePos == -1) + closePos = int(i); + else + closePos = INT_MAX; + } + } + if (openPos != -1 && openPos != INT_MAX + && closePos != -1 && closePos != INT_MAX + && openPos < closePos) { + std::string result(message); + result[openPos] = '('; + result[closePos] = ')'; + return result; + } + + return message; +} + +NORETURN void InStream::quit(TResult result, const char *msg) { + if (TestlibFinalizeGuard::alive) + testlibFinalizeGuard.quitCount++; + + std::string message(msg); + message = trim(message); + + if (__testlib_hasTestCase) { + if (result != _ok) + message = __testlib_appendMessage(message, "test case " + vtos(__testlib_testCase)); + else { + if (__testlib_testCase == 1) + message = __testlib_appendMessage(message, vtos(__testlib_testCase) + " test case"); + else + message = __testlib_appendMessage(message, vtos(__testlib_testCase) + " test cases"); + } + } + + // You can change maxMessageLength. + // Example: 'inf.maxMessageLength = 1024 * 1024;'. + if (message.length() > maxMessageLength) { + std::string warn = "message length exceeds " + vtos(maxMessageLength) + + ", the message is truncated: "; + message = warn + message.substr(0, maxMessageLength - warn.length()); + } + +#ifndef ENABLE_UNEXPECTED_EOF + if (result == _unexpected_eof) + result = _pe; +#endif + + if (testlibMode == _scorer && result != _fail) + quits(_fail, "Scorer should return points only. Don't use a quit function."); + + if (mode != _output && result != _fail) { + if (mode == _input && testlibMode == _validator && lastLine != -1) + quits(_fail, __testlib_appendMessage(__testlib_appendMessage(message, name), "line " + vtos(lastLine))); + else + quits(_fail, __testlib_appendMessage(message, name)); + } + + std::FILE *resultFile; + std::string errorName; + + if (__testlib_shouldCheckDirt(result)) { + if (testlibMode != _interactor && !ouf.seekEof()) + quit(_dirt, "Extra information in the output file"); + } + + int pctype = result - _partially; + bool isPartial = false; + + switch (result) { + case _ok: + errorName = "ok "; + quitscrS(LightGreen, errorName); + break; + case _wa: + errorName = "wrong answer "; + quitscrS(LightRed, errorName); + break; + case _pe: + errorName = "wrong output format "; + quitscrS(LightRed, errorName); + break; + case _fail: + errorName = "FAIL "; + quitscrS(LightRed, errorName); + break; + case _dirt: + errorName = "wrong output format "; + quitscrS(LightCyan, errorName); + result = _pe; + break; + case _points: + errorName = "points "; + quitscrS(LightYellow, errorName); + break; + case _unexpected_eof: + errorName = "unexpected eof "; + quitscrS(LightCyan, errorName); + break; + default: + if (result >= _partially) { + errorName = format("partially correct (%d) ", pctype); + isPartial = true; + quitscrS(LightYellow, errorName); + } else + quit(_fail, "What is the code ??? "); + } + + if (resultName != "") { + resultFile = std::fopen(resultName.c_str(), "w"); + if (resultFile == NULL) { + resultName = ""; + quit(_fail, "Can not write to the result file"); + } + if (appesMode) { + std::fprintf(resultFile, ""); + if (isPartial) + std::fprintf(resultFile, "", + outcomes[(int) _partially].c_str(), pctype); + else { + if (result != _points) + std::fprintf(resultFile, "", outcomes[(int) result].c_str()); + else { + if (__testlib_points == std::numeric_limits::infinity()) + quit(_fail, "Expected points, but infinity found"); + std::string stringPoints = removeDoubleTrailingZeroes(format("%.10f", __testlib_points)); + std::fprintf(resultFile, "", + outcomes[(int) result].c_str(), stringPoints.c_str()); + } + } + xmlSafeWrite(resultFile, __testlib_toPrintableMessage(message).c_str()); + std::fprintf(resultFile, "\n"); + } else + std::fprintf(resultFile, "%s", __testlib_toPrintableMessage(message).c_str()); + if (NULL == resultFile || fclose(resultFile) != 0) { + resultName = ""; + quit(_fail, "Can not write to the result file"); + } + } + + quitscr(LightGray, __testlib_toPrintableMessage(message).c_str()); + std::fprintf(stderr, "\n"); + + inf.close(); + ouf.close(); + ans.close(); + if (tout.is_open()) + tout.close(); + + textColor(LightGray); + + if (resultName != "") + std::fprintf(stderr, "See file to check exit message\n"); + + halt(resultExitCode(result)); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +NORETURN void InStream::quitf(TResult result, const char *msg, ...) { + FMT_TO_RESULT(msg, msg, message); + InStream::quit(result, message.c_str()); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +void InStream::quitif(bool condition, TResult result, const char *msg, ...) { + if (condition) { + FMT_TO_RESULT(msg, msg, message); + InStream::quit(result, message.c_str()); + } +} + +NORETURN void InStream::quits(TResult result, std::string msg) { + InStream::quit(result, msg.c_str()); +} + +void InStream::xmlSafeWrite(std::FILE *file, const char *msg) { + size_t lmsg = strlen(msg); + for (size_t i = 0; i < lmsg; i++) { + if (msg[i] == '&') { + std::fprintf(file, "%s", "&"); + continue; + } + if (msg[i] == '<') { + std::fprintf(file, "%s", "<"); + continue; + } + if (msg[i] == '>') { + std::fprintf(file, "%s", ">"); + continue; + } + if (msg[i] == '"') { + std::fprintf(file, "%s", """); + continue; + } + if (0 <= msg[i] && msg[i] <= 31) { + std::fprintf(file, "%c", '.'); + continue; + } + std::fprintf(file, "%c", msg[i]); + } +} + +void InStream::quitscrS(WORD color, std::string msg) { + quitscr(color, msg.c_str()); +} + +void InStream::quitscr(WORD color, const char *msg) { + if (resultName == "") { + textColor(color); + std::fprintf(stderr, "%s", msg); + textColor(LightGray); + } +} + +void InStream::reset(std::FILE *file) { + if (opened && stdfile) + quit(_fail, "Can't reset standard handle"); + + if (opened) + close(); + + if (!stdfile && NULL == file) + if (NULL == (file = std::fopen(name.c_str(), "rb"))) { + if (mode == _output) + quits(_pe, std::string("Output file not found: \"") + name + "\""); + + if (mode == _answer) + quits(_fail, std::string("Answer file not found: \"") + name + "\""); + } + + if (NULL != file) { + opened = true; + __testlib_set_binary(file); + + if (stdfile) + reader = new FileInputStreamReader(file, name); + else + reader = new BufferedFileInputStreamReader(file, name); + } else { + opened = false; + reader = NULL; + } +} + +void InStream::init(std::string fileName, TMode mode) { + opened = false; + name = fileName; + stdfile = false; + this->mode = mode; + + std::ifstream stream; + stream.open(fileName.c_str(), std::ios::in); + if (stream.is_open()) { + std::streampos start = stream.tellg(); + stream.seekg(0, std::ios::end); + std::streampos end = stream.tellg(); + size_t fileSize = size_t(end - start); + stream.close(); + + // You can change maxFileSize. + // Example: 'inf.maxFileSize = 256 * 1024 * 1024;'. + if (fileSize > maxFileSize) + quitf(_pe, "File size exceeds %d bytes, size is %d", int(maxFileSize), int(fileSize)); + } + + reset(); + skipBom(); +} + +void InStream::init(std::FILE *f, TMode mode) { + opened = false; + name = "untitled"; + this->mode = mode; + + if (f == stdin) + name = "stdin", stdfile = true; + if (f == stdout) + name = "stdout", stdfile = true; + if (f == stderr) + name = "stderr", stdfile = true; + + reset(f); + skipBom(); +} + +void InStream::skipBom() { + const std::string utf8Bom = "\xEF\xBB\xBF"; + size_t index = 0; + while (index < utf8Bom.size() && curChar() == utf8Bom[index]) { + index++; + skipChar(); + } + if (index < utf8Bom.size()) { + while (index != 0) { + unreadChar(utf8Bom[index - 1]); + index--; + } + } +} + +char InStream::curChar() { + return char(reader->curChar()); +} + +char InStream::nextChar() { + return char(reader->nextChar()); +} + +char InStream::readChar() { + return nextChar(); +} + +char InStream::readChar(char c) { + lastLine = reader->getLine(); + char found = readChar(); + if (c != found) { + if (!isEoln(found)) + quit(_pe, ("Unexpected character '" + std::string(1, found) + "', but '" + std::string(1, c) + + "' expected").c_str()); + else + quit(_pe, ("Unexpected character " + ("#" + vtos(int(found))) + ", but '" + std::string(1, c) + + "' expected").c_str()); + } + return found; +} + +char InStream::readSpace() { + return readChar(' '); +} + +void InStream::unreadChar(char c) { + reader->unreadChar(c); +} + +void InStream::skipChar() { + reader->skipChar(); +} + +void InStream::skipBlanks() { + while (isBlanks(reader->curChar())) + reader->skipChar(); +} + +std::string InStream::readWord() { + readWordTo(_tmpReadToken); + return _tmpReadToken; +} + +void InStream::readWordTo(std::string &result) { + if (!strict) + skipBlanks(); + + lastLine = reader->getLine(); + int cur = reader->nextChar(); + + if (cur == EOFC) + quit(_unexpected_eof, "Unexpected end of file - token expected"); + + if (isBlanks(cur)) + quit(_pe, "Unexpected white-space - token expected"); + + result.clear(); + + while (!(isBlanks(cur) || cur == EOFC)) { + result += char(cur); + + // You can change maxTokenLength. + // Example: 'inf.maxTokenLength = 128 * 1024 * 1024;'. + if (result.length() > maxTokenLength) + quitf(_pe, "Length of token exceeds %d, token is '%s...'", int(maxTokenLength), + __testlib_part(result).c_str()); + + cur = reader->nextChar(); + } + + reader->unreadChar(cur); + + if (result.length() == 0) + quit(_unexpected_eof, "Unexpected end of file or white-space - token expected"); +} + +std::string InStream::readToken() { + return readWord(); +} + +void InStream::readTokenTo(std::string &result) { + readWordTo(result); +} + +static std::string __testlib_part(const std::string &s) { + std::string t; + for (size_t i = 0; i < s.length(); i++) + if (s[i] != '\0') + t += s[i]; + else + t += '~'; + if (t.length() <= 64) + return t; + else + return t.substr(0, 30) + "..." + t.substr(s.length() - 31, 31); +} + +#define __testlib_readMany(readMany, readOne, typeName, space) \ + if (size < 0) \ + quit(_fail, #readMany ": size should be non-negative."); \ + if (size > 100000000) \ + quit(_fail, #readMany ": size should be at most 100000000."); \ + \ + std::vector result(size); \ + readManyIteration = indexBase; \ + \ + for (int i = 0; i < size; i++) \ + { \ + result[i] = readOne; \ + readManyIteration++; \ + if (strict && space && i + 1 < size) \ + readSpace(); \ + } \ + \ + readManyIteration = NO_INDEX; \ + return result; \ + + +std::string InStream::readWord(const pattern &p, const std::string &variableName) { + readWordTo(_tmpReadToken); + if (!p.matches(_tmpReadToken)) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, + ("Token \"" + __testlib_part(_tmpReadToken) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token parameter [name=" + variableName + "] equals to \"" + __testlib_part(_tmpReadToken) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Token element [index=" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(_tmpReadToken) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token element " + variableName + "[" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(_tmpReadToken) + "\", doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + } + } + return _tmpReadToken; +} + +std::vector +InStream::readWords(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readWords, readWord(p, variablesName), std::string, true); +} + +std::vector InStream::readWords(int size, int indexBase) { + __testlib_readMany(readWords, readWord(), std::string, true); +} + +std::string InStream::readWord(const std::string &ptrn, const std::string &variableName) { + return readWord(pattern(ptrn), variableName); +} + +std::vector +InStream::readWords(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readWords, readWord(p, variablesName), std::string, true); +} + +std::string InStream::readToken(const pattern &p, const std::string &variableName) { + return readWord(p, variableName); +} + +std::vector +InStream::readTokens(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readTokens, readToken(p, variablesName), std::string, true); +} + +std::vector InStream::readTokens(int size, int indexBase) { + __testlib_readMany(readTokens, readToken(), std::string, true); +} + +std::string InStream::readToken(const std::string &ptrn, const std::string &variableName) { + return readWord(ptrn, variableName); +} + +std::vector +InStream::readTokens(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readTokens, readWord(p, variablesName), std::string, true); +} + +void InStream::readWordTo(std::string &result, const pattern &p, const std::string &variableName) { + readWordTo(result); + if (!p.matches(result)) { + if (variableName.empty()) + quit(_wa, ("Token \"" + __testlib_part(result) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token parameter [name=" + variableName + "] equals to \"" + __testlib_part(result) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } +} + +void InStream::readWordTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + return readWordTo(result, pattern(ptrn), variableName); +} + +void InStream::readTokenTo(std::string &result, const pattern &p, const std::string &variableName) { + return readWordTo(result, p, variableName); +} + +void InStream::readTokenTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + return readWordTo(result, ptrn, variableName); +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static inline bool equals(long long integer, const char *s) { + if (integer == LLONG_MIN) + return strcmp(s, "-9223372036854775808") == 0; + + if (integer == 0LL) + return strcmp(s, "0") == 0; + + size_t length = strlen(s); + + if (length == 0) + return false; + + if (integer < 0 && s[0] != '-') + return false; + + if (integer < 0) + s++, length--, integer = -integer; + + if (length == 0) + return false; + + while (integer > 0) { + int digit = int(integer % 10); + + if (s[length - 1] != '0' + digit) + return false; + + length--; + integer /= 10; + } + + return length == 0; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static inline bool equals(unsigned long long integer, const char *s) { + if (integer == ULLONG_MAX) + return strcmp(s, "18446744073709551615") == 0; + + if (integer == 0ULL) + return strcmp(s, "0") == 0; + + size_t length = strlen(s); + + if (length == 0) + return false; + + while (integer > 0) { + int digit = int(integer % 10); + + if (s[length - 1] != '0' + digit) + return false; + + length--; + integer /= 10; + } + + return length == 0; +} + +static inline double stringToDouble(InStream &in, const char *buffer) { + double retval; + + size_t length = strlen(buffer); + + int minusCount = 0; + int plusCount = 0; + int decimalPointCount = 0; + int digitCount = 0; + int eCount = 0; + + for (size_t i = 0; i < length; i++) { + if (('0' <= buffer[i] && buffer[i] <= '9') || buffer[i] == '.' + || buffer[i] == 'e' || buffer[i] == 'E' + || buffer[i] == '-' || buffer[i] == '+') { + if ('0' <= buffer[i] && buffer[i] <= '9') + digitCount++; + if (buffer[i] == 'e' || buffer[i] == 'E') + eCount++; + if (buffer[i] == '-') + minusCount++; + if (buffer[i] == '+') + plusCount++; + if (buffer[i] == '.') + decimalPointCount++; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + } + + // If for sure is not a number in standard notation or in e-notation. + if (digitCount == 0 || minusCount > 2 || plusCount > 2 || decimalPointCount > 1 || eCount > 1) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + char *suffix = new char[length + 1]; + std::memset(suffix, 0, length + 1); + int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix); + bool empty = strlen(suffix) == 0; + delete[] suffix; + + if (scanned == 1 || (scanned == 2 && empty)) { + if (__testlib_isNaN(retval)) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + return retval; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline double stringToDouble(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToDouble(in, buffer.c_str()); +} + +static inline double stringToStrictDouble(InStream &in, const char *buffer, + int minAfterPointDigitCount, int maxAfterPointDigitCount) { + if (minAfterPointDigitCount < 0) + in.quit(_fail, "stringToStrictDouble: minAfterPointDigitCount should be non-negative."); + + if (minAfterPointDigitCount > maxAfterPointDigitCount) + in.quit(_fail, + "stringToStrictDouble: minAfterPointDigitCount should be less or equal to maxAfterPointDigitCount."); + + double retval; + + size_t length = strlen(buffer); + + if (length == 0 || length > 1000) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (buffer[0] != '-' && (buffer[0] < '0' || buffer[0] > '9')) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + int pointPos = -1; + for (size_t i = 1; i + 1 < length; i++) { + if (buffer[i] == '.') { + if (pointPos > -1) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + pointPos = int(i); + } + if (buffer[i] != '.' && (buffer[i] < '0' || buffer[i] > '9')) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + } + + if (buffer[length - 1] < '0' || buffer[length - 1] > '9') + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + int afterDigitsCount = (pointPos == -1 ? 0 : int(length) - pointPos - 1); + if (afterDigitsCount < minAfterPointDigitCount || afterDigitsCount > maxAfterPointDigitCount) + in.quit(_pe, ("Expected strict double with number of digits after point in range [" + + vtos(minAfterPointDigitCount) + + "," + + vtos(maxAfterPointDigitCount) + + "], but \"" + __testlib_part(buffer) + "\" found").c_str() + ); + + int firstDigitPos = -1; + for (size_t i = 0; i < length; i++) + if (buffer[i] >= '0' && buffer[i] <= '9') { + firstDigitPos = int(i); + break; + } + + if (firstDigitPos > 1 || firstDigitPos == -1) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (buffer[firstDigitPos] == '0' && firstDigitPos + 1 < int(length) + && buffer[firstDigitPos + 1] >= '0' && buffer[firstDigitPos + 1] <= '9') + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + char *suffix = new char[length + 1]; + std::memset(suffix, 0, length + 1); + int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix); + bool empty = strlen(suffix) == 0; + delete[] suffix; + + if (scanned == 1 || (scanned == 2 && empty)) { + if (__testlib_isNaN(retval) || __testlib_isInfinite(retval)) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + if (buffer[0] == '-' && retval >= 0) + in.quit(_pe, ("Redundant minus in \"" + __testlib_part(buffer) + "\" found").c_str()); + return retval; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline double stringToStrictDouble(InStream &in, const std::string& buffer, + int minAfterPointDigitCount, int maxAfterPointDigitCount) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToStrictDouble(in, buffer.c_str(), minAfterPointDigitCount, maxAfterPointDigitCount); +} + +static inline long long stringToLongLong(InStream &in, const char *buffer) { + if (strcmp(buffer, "-9223372036854775808") == 0) + return LLONG_MIN; + + bool minus = false; + size_t length = strlen(buffer); + + if (length > 1 && buffer[0] == '-') + minus = true; + + if (length > 20) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + long long retval = 0LL; + + int zeroes = 0; + bool processingZeroes = true; + + for (int i = (minus ? 1 : 0); i < int(length); i++) { + if (buffer[i] == '0' && processingZeroes) + zeroes++; + else + processingZeroes = false; + + if (buffer[i] < '0' || buffer[i] > '9') + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + retval = retval * 10 + (buffer[i] - '0'); + } + + if (retval < 0) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if ((zeroes > 0 && (retval != 0 || minus)) || zeroes > 1) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + retval = (minus ? -retval : +retval); + + if (length < 19) + return retval; + + if (equals(retval, buffer)) + return retval; + else + in.quit(_pe, ("Expected int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline long long stringToLongLong(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToLongLong(in, buffer.c_str()); +} + +static inline unsigned long long stringToUnsignedLongLong(InStream &in, const char *buffer) { + size_t length = strlen(buffer); + + if (length > 20) + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + if (length > 1 && buffer[0] == '0') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + unsigned long long retval = 0LL; + for (int i = 0; i < int(length); i++) { + if (buffer[i] < '0' || buffer[i] > '9') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + retval = retval * 10 + (buffer[i] - '0'); + } + + if (length < 19) + return retval; + + if (length == 20 && strcmp(buffer, "18446744073709551615") > 0) + in.quit(_pe, ("Expected unsigned int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (equals(retval, buffer)) + return retval; + else + in.quit(_pe, ("Expected unsigned int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline long long stringToUnsignedLongLong(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToUnsignedLongLong(in, buffer.c_str()); +} + +int InStream::readInteger() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int32 expected"); + + readWordTo(_tmpReadToken); + + long long value = stringToLongLong(*this, _tmpReadToken); + if (value < INT_MIN || value > INT_MAX) + quit(_pe, ("Expected int32, but \"" + __testlib_part(_tmpReadToken) + "\" found").c_str()); + + return int(value); +} + +long long InStream::readLong() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int64 expected"); + + readWordTo(_tmpReadToken); + + return stringToLongLong(*this, _tmpReadToken); +} + +unsigned long long InStream::readUnsignedLong() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int64 expected"); + + readWordTo(_tmpReadToken); + + return stringToUnsignedLongLong(*this, _tmpReadToken); +} + +long long InStream::readLong(long long minv, long long maxv, const std::string &variableName) { + long long result = readLong(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, ("Integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, + ("Integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +std::vector +InStream::readLongs(int size, long long minv, long long maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readLongs, readLong(minv, maxv, variablesName), long long, true) +} + +std::vector InStream::readLongs(int size, int indexBase) { + __testlib_readMany(readLongs, readLong(), long long, true) +} + +unsigned long long +InStream::readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName) { + unsigned long long result = readUnsignedLong(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, + ("Unsigned integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, + ("Unsigned integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, + ("Unsigned integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, ("Unsigned integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + + "] equals to " + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +std::vector InStream::readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readUnsignedLongs, readUnsignedLong(minv, maxv, variablesName), unsigned long long, true) +} + +std::vector InStream::readUnsignedLongs(int size, int indexBase) { + __testlib_readMany(readUnsignedLongs, readUnsignedLong(), unsigned long long, true) +} + +unsigned long long +InStream::readLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName) { + return readUnsignedLong(minv, maxv, variableName); +} + +int InStream::readInt() { + return readInteger(); +} + +int InStream::readInt(int minv, int maxv, const std::string &variableName) { + int result = readInt(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, ("Integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, + ("Integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +int InStream::readInteger(int minv, int maxv, const std::string &variableName) { + return readInt(minv, maxv, variableName); +} + +std::vector InStream::readInts(int size, int minv, int maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readInts, readInt(minv, maxv, variablesName), int, true) +} + +std::vector InStream::readInts(int size, int indexBase) { + __testlib_readMany(readInts, readInt(), int, true) +} + +std::vector InStream::readIntegers(int size, int minv, int maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readIntegers, readInt(minv, maxv, variablesName), int, true) +} + +std::vector InStream::readIntegers(int size, int indexBase) { + __testlib_readMany(readIntegers, readInt(), int, true) +} + +double InStream::readReal() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - double expected"); + + return stringToDouble(*this, readWord()); +} + +double InStream::readDouble() { + return readReal(); +} + +double InStream::readReal(double minv, double maxv, const std::string &variableName) { + double result = readReal(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Double " + vtos(result) + " violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + else + quit(_wa, ("Double parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Double element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + else + quit(_wa, + ("Double element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit( + doubleDelta(minv, result) < ValidatorBoundsHit::EPS, + doubleDelta(maxv, result) < ValidatorBoundsHit::EPS + )); + + return result; +} + +std::vector +InStream::readReals(int size, double minv, double maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readReals, readReal(minv, maxv, variablesName), double, true) +} + +std::vector InStream::readReals(int size, int indexBase) { + __testlib_readMany(readReals, readReal(), double, true) +} + +double InStream::readDouble(double minv, double maxv, const std::string &variableName) { + return readReal(minv, maxv, variableName); +} + +std::vector +InStream::readDoubles(int size, double minv, double maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readDoubles, readDouble(minv, maxv, variablesName), double, true) +} + +std::vector InStream::readDoubles(int size, int indexBase) { + __testlib_readMany(readDoubles, readDouble(), double, true) +} + +double InStream::readStrictReal(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName) { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - strict double expected"); + + double result = stringToStrictDouble(*this, readWord(), minAfterPointDigitCount, maxAfterPointDigitCount); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Strict double " + vtos(result) + " violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + else + quit(_wa, + ("Strict double parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Strict double element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + else + quit(_wa, ("Strict double element " + std::string(variableName) + "[" + vtos(readManyIteration) + + "] equals to " + vtos(result) + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit( + doubleDelta(minv, result) < ValidatorBoundsHit::EPS, + doubleDelta(maxv, result) < ValidatorBoundsHit::EPS + )); + + return result; +} + +std::vector InStream::readStrictReals(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrictReals, + readStrictReal(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName), + double, true) +} + +double InStream::readStrictDouble(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName) { + return readStrictReal(minv, maxv, + minAfterPointDigitCount, maxAfterPointDigitCount, + variableName); +} + +std::vector InStream::readStrictDoubles(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrictDoubles, + readStrictDouble(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName), + double, true) +} + +bool InStream::eof() { + if (!strict && NULL == reader) + return true; + + return reader->eof(); +} + +bool InStream::seekEof() { + if (!strict && NULL == reader) + return true; + skipBlanks(); + return eof(); +} + +bool InStream::eoln() { + if (!strict && NULL == reader) + return true; + + int c = reader->nextChar(); + + if (!strict) { + if (c == EOFC) + return true; + + if (c == CR) { + c = reader->nextChar(); + + if (c != LF) { + reader->unreadChar(c); + reader->unreadChar(CR); + return false; + } else + return true; + } + + if (c == LF) + return true; + + reader->unreadChar(c); + return false; + } else { + bool returnCr = false; + +#if (defined(ON_WINDOWS) && !defined(FOR_LINUX)) || defined(FOR_WINDOWS) + if (c != CR) { + reader->unreadChar(c); + return false; + } else { + if (!returnCr) + returnCr = true; + c = reader->nextChar(); + } +#endif + if (c != LF) { + reader->unreadChar(c); + if (returnCr) + reader->unreadChar(CR); + return false; + } + + return true; + } +} + +void InStream::readEoln() { + lastLine = reader->getLine(); + if (!eoln()) + quit(_pe, "Expected EOLN"); +} + +void InStream::readEof() { + lastLine = reader->getLine(); + if (!eof()) + quit(_pe, "Expected EOF"); + + if (TestlibFinalizeGuard::alive && this == &inf) + testlibFinalizeGuard.readEofCount++; +} + +bool InStream::seekEoln() { + if (!strict && NULL == reader) + return true; + + int cur; + do { + cur = reader->nextChar(); + } while (cur == SPACE || cur == TAB); + + reader->unreadChar(cur); + return eoln(); +} + +void InStream::nextLine() { + readLine(); +} + +void InStream::readStringTo(std::string &result) { + if (NULL == reader) + quit(_pe, "Expected line"); + + result.clear(); + + for (;;) { + int cur = reader->curChar(); + + if (cur == LF || cur == EOFC) + break; + + if (cur == CR) { + cur = reader->nextChar(); + if (reader->curChar() == LF) { + reader->unreadChar(cur); + break; + } + } + + lastLine = reader->getLine(); + result += char(reader->nextChar()); + } + + if (strict) + readEoln(); + else + eoln(); +} + +std::string InStream::readString() { + readStringTo(_tmpReadToken); + return _tmpReadToken; +} + +std::vector InStream::readStrings(int size, int indexBase) { + __testlib_readMany(readStrings, readString(), std::string, false) +} + +void InStream::readStringTo(std::string &result, const pattern &p, const std::string &variableName) { + readStringTo(result); + if (!p.matches(result)) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Line \"" + __testlib_part(result) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Line [name=" + variableName + "] equals to \"" + __testlib_part(result) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } else { + if (variableName.empty()) + quit(_wa, + ("Line element [index=" + vtos(readManyIteration) + "] equals to \"" + __testlib_part(result) + + "\" doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + else + quit(_wa, + ("Line element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(result) + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } + } +} + +void InStream::readStringTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + readStringTo(result, pattern(ptrn), variableName); +} + +std::string InStream::readString(const pattern &p, const std::string &variableName) { + readStringTo(_tmpReadToken, p, variableName); + return _tmpReadToken; +} + +std::vector +InStream::readStrings(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrings, readString(p, variablesName), std::string, false) +} + +std::string InStream::readString(const std::string &ptrn, const std::string &variableName) { + readStringTo(_tmpReadToken, ptrn, variableName); + return _tmpReadToken; +} + +std::vector +InStream::readStrings(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readStrings, readString(p, variablesName), std::string, false) +} + +void InStream::readLineTo(std::string &result) { + readStringTo(result); +} + +std::string InStream::readLine() { + return readString(); +} + +std::vector InStream::readLines(int size, int indexBase) { + __testlib_readMany(readLines, readString(), std::string, false) +} + +void InStream::readLineTo(std::string &result, const pattern &p, const std::string &variableName) { + readStringTo(result, p, variableName); +} + +void InStream::readLineTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + readStringTo(result, ptrn, variableName); +} + +std::string InStream::readLine(const pattern &p, const std::string &variableName) { + return readString(p, variableName); +} + +std::vector +InStream::readLines(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readLines, readString(p, variablesName), std::string, false) +} + +std::string InStream::readLine(const std::string &ptrn, const std::string &variableName) { + return readString(ptrn, variableName); +} + +std::vector +InStream::readLines(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readLines, readString(p, variablesName), std::string, false) +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +void InStream::ensuref(bool cond, const char *format, ...) { + if (!cond) { + FMT_TO_RESULT(format, format, message); + this->__testlib_ensure(cond, message); + } +} + +void InStream::__testlib_ensure(bool cond, std::string message) { + if (!cond) + this->quit(_wa, message.c_str()); +} + +void InStream::close() { + if (NULL != reader) { + reader->close(); + delete reader; + reader = NULL; + } + + opened = false; +} + +NORETURN void quit(TResult result, const std::string &msg) { + ouf.quit(result, msg.c_str()); +} + +NORETURN void quit(TResult result, const char *msg) { + ouf.quit(result, msg); +} + +NORETURN void __testlib_quitp(double points, const char *message) { + __testlib_points = points; + std::string stringPoints = removeDoubleTrailingZeroes(format("%.10f", points)); + + std::string quitMessage; + if (NULL == message || 0 == strlen(message)) + quitMessage = stringPoints; + else + quitMessage = stringPoints + " " + message; + + quit(_points, quitMessage.c_str()); +} + +NORETURN void __testlib_quitp(int points, const char *message) { + __testlib_points = points; + std::string stringPoints = format("%d", points); + + std::string quitMessage; + if (NULL == message || 0 == strlen(message)) + quitMessage = stringPoints; + else + quitMessage = stringPoints + " " + message; + + quit(_points, quitMessage.c_str()); +} + +NORETURN void quitp(float points, const std::string &message = "") { + __testlib_quitp(double(points), message.c_str()); +} + +NORETURN void quitp(double points, const std::string &message = "") { + __testlib_quitp(points, message.c_str()); +} + +NORETURN void quitp(long double points, const std::string &message = "") { + __testlib_quitp(double(points), message.c_str()); +} + +NORETURN void quitp(int points, const std::string &message = "") { + __testlib_quitp(points, message.c_str()); +} + +NORETURN void quitpi(const std::string &points_info, const std::string &message = "") { + if (points_info.find(' ') != std::string::npos) + quit(_fail, "Parameter 'points_info' can't contain spaces"); + if (message.empty()) + quit(_points, ("points_info=" + points_info).c_str()); + else + quit(_points, ("points_info=" + points_info + " " + message).c_str()); +} + +template +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +NORETURN void quitp(F points, const char *format, ...) { + FMT_TO_RESULT(format, format, message); + quitp(points, message); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +NORETURN void quitf(TResult result, const char *format, ...) { + FMT_TO_RESULT(format, format, message); + quit(result, message); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +void quitif(bool condition, TResult result, const char *format, ...) { + if (condition) { + FMT_TO_RESULT(format, format, message); + quit(result, message); + } +} + +NORETURN void __testlib_help() { + InStream::textColor(InStream::LightCyan); + std::fprintf(stderr, "TESTLIB %s, https://github.com/MikeMirzayanov/testlib/ ", VERSION); + std::fprintf(stderr, "by Mike Mirzayanov, copyright(c) 2005-2020\n"); + std::fprintf(stderr, "Checker name: \"%s\"\n", checkerName.c_str()); + InStream::textColor(InStream::LightGray); + + std::fprintf(stderr, "\n"); + std::fprintf(stderr, "Latest features: \n"); + for (size_t i = 0; i < sizeof(latestFeatures) / sizeof(char *); i++) { + std::fprintf(stderr, "*) %s\n", latestFeatures[i]); + } + std::fprintf(stderr, "\n"); + + std::fprintf(stderr, "Program must be run with the following arguments: \n"); + std::fprintf(stderr, " [--testset testset] [--group group] [ [<-appes>]]\n\n"); + + __testlib_exitCode = FAIL_EXIT_CODE; + std::exit(FAIL_EXIT_CODE); +} + +static void __testlib_ensuresPreconditions() { + // testlib assumes: sizeof(int) = 4. + __TESTLIB_STATIC_ASSERT(sizeof(int) == 4); + + // testlib assumes: INT_MAX == 2147483647. + __TESTLIB_STATIC_ASSERT(INT_MAX == 2147483647); + + // testlib assumes: sizeof(long long) = 8. + __TESTLIB_STATIC_ASSERT(sizeof(long long) == 8); + + // testlib assumes: sizeof(double) = 8. + __TESTLIB_STATIC_ASSERT(sizeof(double) == 8); + + // testlib assumes: no -ffast-math. + if (!__testlib_isNaN(+__testlib_nan())) + quit(_fail, "Function __testlib_isNaN is not working correctly: possible reason is '-ffast-math'"); + if (!__testlib_isNaN(-__testlib_nan())) + quit(_fail, "Function __testlib_isNaN is not working correctly: possible reason is '-ffast-math'"); +} + +std::string __testlib_testset; + +std::string getTestset() { + return __testlib_testset; +} + +std::string __testlib_group; + +std::string getGroup() { + return __testlib_group; +} + +static void __testlib_set_testset_and_group(int argc, char* argv[]) { + for (int i = 1; i < argc; i++) { + if (!strcmp("--testset", argv[i])) { + if (i + 1 < argc && strlen(argv[i + 1]) > 0) + __testlib_testset = argv[++i]; + else + quit(_fail, std::string("Expected non-empty testset after --testset command line parameter")); + } else if (!strcmp("--group", argv[i])) { + if (i + 1 < argc) + __testlib_group = argv[++i]; + else + quit(_fail, std::string("Expected group after --group command line parameter")); + } + } +} + +void registerGen(int argc, char *argv[], int randomGeneratorVersion) { + if (randomGeneratorVersion < 0 || randomGeneratorVersion > 1) + quitf(_fail, "Random generator version is expected to be 0 or 1."); + random_t::version = randomGeneratorVersion; + + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _generator; + __testlib_set_binary(stdin); + rnd.setSeed(argc, argv); + +#if __cplusplus > 199711L || defined(_MSC_VER) + prepareOpts(argc, argv); +#endif +} + +#ifdef USE_RND_AS_BEFORE_087 +void registerGen(int argc, char* argv[]) +{ + registerGen(argc, argv, 0); +} +#else +#ifdef __GNUC__ +#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 4)) +__attribute__ ((deprecated("Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." +" The third parameter stands for the random generator version." +" If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." +" Version 1 has been released on Spring, 2013. Use it to write new generators."))) +#else +__attribute__ ((deprecated)) +#endif +#endif +#ifdef _MSC_VER +__declspec(deprecated("Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." + " The third parameter stands for the random generator version." + " If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." + " Version 1 has been released on Spring, 2013. Use it to write new generators.")) +#endif +void registerGen(int argc, char *argv[]) { + std::fprintf(stderr, "Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." + " The third parameter stands for the random generator version." + " If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." + " Version 1 has been released on Spring, 2013. Use it to write new generators.\n\n"); + registerGen(argc, argv, 0); +} +#endif + +void registerInteraction(int argc, char *argv[]) { + __testlib_ensuresPreconditions(); + __testlib_set_testset_and_group(argc, argv); + TestlibFinalizeGuard::registered = true; + + testlibMode = _interactor; + __testlib_set_binary(stdin); + + if (argc > 1 && !strcmp("--help", argv[1])) + __testlib_help(); + + if (argc < 3 || argc > 6) { + quit(_fail, std::string("Program must be run with the following arguments: ") + + std::string(" [ [ [<-appes>]]]") + + "\nUse \"--help\" to get help information"); + } + + if (argc <= 4) { + resultName = ""; + appesMode = false; + } + +#ifndef EJUDGE + if (argc == 5) { + resultName = argv[4]; + appesMode = false; + } + + if (argc == 6) { + if (strcmp("-APPES", argv[5]) && strcmp("-appes", argv[5])) { + quit(_fail, std::string("Program must be run with the following arguments: ") + + " [ [<-appes>]]"); + } else { + resultName = argv[4]; + appesMode = true; + } + } +#endif + + inf.init(argv[1], _input); + + tout.open(argv[2], std::ios_base::out); + if (tout.fail() || !tout.is_open()) + quit(_fail, std::string("Can not write to the test-output-file '") + argv[2] + std::string("'")); + + ouf.init(stdin, _output); + + if (argc >= 4) + ans.init(argv[3], _answer); + else + ans.name = "unopened answer stream"; +} + +void registerValidation() { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _validator; + + __testlib_set_binary(stdin); + __testlib_set_binary(stdout); + __testlib_set_binary(stderr); + + inf.init(stdin, _input); + inf.strict = true; +} + +void registerValidation(int argc, char *argv[]) { + registerValidation(); + __testlib_set_testset_and_group(argc, argv); + + validator.initialize(); + TestlibFinalizeGuard::registered = true; + + std::string comment = "Validator must be run with the following arguments:" + " [--testset testset]" + " [--group group]" + " [--testOverviewLogFileName fileName]" + " [--testMarkupFileName fileName]" + " [--testCase testCase]" + " [--testCaseFileName fileName]" + ; + + for (int i = 1; i < argc; i++) { + if (!strcmp("--testset", argv[i])) { + if (i + 1 < argc && strlen(argv[i + 1]) > 0) + validator.setTestset(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--group", argv[i])) { + if (i + 1 < argc) + validator.setGroup(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testOverviewLogFileName", argv[i])) { + if (i + 1 < argc) + validator.setTestOverviewLogFileName(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testMarkupFileName", argv[i])) { + if (i + 1 < argc) + validator.setTestMarkupFileName(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testCase", argv[i])) { + if (i + 1 < argc) { + long long testCase = stringToLongLong(inf, argv[++i]); + if (testCase < 1 || testCase >= __TESTLIB_MAX_TEST_CASE) + quit(_fail, format("Argument testCase should be between 1 and %d, but ", __TESTLIB_MAX_TEST_CASE) + + toString(testCase) + " found"); + validator.setTestCase(int(testCase)); + } else + quit(_fail, comment); + } + if (!strcmp("--testCaseFileName", argv[i])) { + if (i + 1 < argc) { + validator.setTestCaseFileName(argv[++i]); + } else + quit(_fail, comment); + } + } +} + +void addFeature(const std::string &feature) { + if (testlibMode != _validator) + quit(_fail, "Features are supported in validators only."); + validator.addFeature(feature); +} + +void feature(const std::string &feature) { + if (testlibMode != _validator) + quit(_fail, "Features are supported in validators only."); + validator.feature(feature); +} + +class Checker { +private: + bool _initialized; + std::string _testset; + std::string _group; + +public: + Checker() : _initialized(false), _testset("tests"), _group() { + } + + void initialize() { + _initialized = true; + } + + std::string testset() const { + if (!_initialized) + __testlib_fail("Checker should be initialized with registerTestlibCmd(argc, argv) instead of registerTestlibCmd() to support checker.testset()"); + return _testset; + } + + std::string group() const { + if (!_initialized) + __testlib_fail("Checker should be initialized with registerTestlibCmd(argc, argv) instead of registerTestlibCmd() to support checker.group()"); + return _group; + } + + void setTestset(const char *const testset) { + _testset = testset; + } + + void setGroup(const char *const group) { + _group = group; + } +} checker; + +void registerTestlibCmd(int argc, char *argv[]) { + __testlib_ensuresPreconditions(); + __testlib_set_testset_and_group(argc, argv); + TestlibFinalizeGuard::registered = true; + + testlibMode = _checker; + __testlib_set_binary(stdin); + + std::vector args(1, argv[0]); + checker.initialize(); + + for (int i = 1; i < argc; i++) { + if (!strcmp("--testset", argv[i])) { + if (i + 1 < argc && strlen(argv[i + 1]) > 0) + checker.setTestset(argv[++i]); + else + quit(_fail, std::string("Expected testset after --testset command line parameter")); + } else if (!strcmp("--group", argv[i])) { + if (i + 1 < argc) + checker.setGroup(argv[++i]); + else + quit(_fail, std::string("Expected group after --group command line parameter")); + } else + args.push_back(argv[i]); + } + + argc = int(args.size()); + if (argc > 1 && "--help" == args[1]) + __testlib_help(); + + if (argc < 4 || argc > 6) { + quit(_fail, std::string("Program must be run with the following arguments: ") + + std::string("[--testset testset] [--group group] [ [<-appes>]]") + + "\nUse \"--help\" to get help information"); + } + + if (argc == 4) { + resultName = ""; + appesMode = false; + } + + if (argc == 5) { + resultName = args[4]; + appesMode = false; + } + + if (argc == 6) { + if ("-APPES" != args[5] && "-appes" != args[5]) { + quit(_fail, std::string("Program must be run with the following arguments: ") + + " [ [<-appes>]]"); + } else { + resultName = args[4]; + appesMode = true; + } + } + + #ifdef BOCA_SUPPORT + inf.init(argv[3], _input); + ouf.init(argv[1], _output); + ans.init(argv[2], _answer); + #else + inf.init(argv[1], _input); + ouf.init(argv[2], _output); + ans.init(argv[3], _answer); + #endif +} + +void registerTestlib(int argc, ...) { + if (argc < 3 || argc > 5) + quit(_fail, std::string("Program must be run with the following arguments: ") + + " [ [<-appes>]]"); + + char **argv = new char *[argc + 1]; + + va_list ap; + va_start(ap, argc); + argv[0] = NULL; + for (int i = 0; i < argc; i++) { + argv[i + 1] = va_arg(ap, char*); + } + va_end(ap); + + registerTestlibCmd(argc + 1, argv); + delete[] argv; +} + +static inline void __testlib_ensure(bool cond, const std::string &msg) { + if (!cond) + quit(_fail, msg.c_str()); +} + +#ifdef __GNUC__ +__attribute__((unused)) +#endif +static inline void __testlib_ensure(bool cond, const char *msg) { + if (!cond) + quit(_fail, msg); +} + +#define ensure(cond) __testlib_ensure(cond, "Condition failed: \"" #cond "\"") +#define STRINGIZE_DETAIL(x) #x +#define STRINGIZE(x) STRINGIZE_DETAIL(x) +#define ensure_ext(cond) __testlib_ensure(cond, "Line " STRINGIZE(__LINE__) ": Condition failed: \"" #cond "\"") + +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +inline void ensuref(bool cond, const char *format, ...) { + if (!cond) { + FMT_TO_RESULT(format, format, message); + __testlib_ensure(cond, message); + } +} + +NORETURN static void __testlib_fail(const std::string &message) { + quitf(_fail, "%s", message.c_str()); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 1, 2))) +#endif +void setName(const char *format, ...) { + FMT_TO_RESULT(format, format, name); + checkerName = name; +} + +/* + * Do not use random_shuffle, because it will produce different result + * for different C++ compilers. + * + * This implementation uses testlib random_t to produce random numbers, so + * it is stable. + */ +template +void shuffle(_RandomAccessIter __first, _RandomAccessIter __last) { + if (__first == __last) return; + for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i) + std::iter_swap(__i, __first + rnd.next(int(__i - __first) + 1)); +} + + +template +#if defined(__GNUC__) && !defined(__clang__) +__attribute__ ((error("Don't use random_shuffle(), use shuffle() instead"))) +#endif +void random_shuffle(_RandomAccessIter, _RandomAccessIter) { + quitf(_fail, "Don't use random_shuffle(), use shuffle() instead"); +} + +#ifdef __GLIBC__ +# define RAND_THROW_STATEMENT throw() +#else +# define RAND_THROW_STATEMENT +#endif + +#if defined(__GNUC__) && !defined(__clang__) + +__attribute__ ((error("Don't use rand(), use rnd.next() instead"))) +#endif +#ifdef _MSC_VER +# pragma warning( disable : 4273 ) +#endif +int rand() RAND_THROW_STATEMENT +{ + quitf(_fail, "Don't use rand(), use rnd.next() instead"); + + /* This line never runs. */ + //throw "Don't use rand(), use rnd.next() instead"; +} + +#if defined(__GNUC__) && !defined(__clang__) + +__attribute__ ((error("Don't use srand(), you should use " +"'registerGen(argc, argv, 1);' to initialize generator seed " +"by hash code of the command line params. The third parameter " +"is randomGeneratorVersion (currently the latest is 1)."))) +#endif +#ifdef _MSC_VER +# pragma warning( disable : 4273 ) +#endif +void srand(unsigned int seed) RAND_THROW_STATEMENT +{ + quitf(_fail, "Don't use srand(), you should use " + "'registerGen(argc, argv, 1);' to initialize generator seed " + "by hash code of the command line params. The third parameter " + "is randomGeneratorVersion (currently the latest is 1) [ignored seed=%u].", seed); +} + +void startTest(int test) { + const std::string testFileName = vtos(test); + if (NULL == freopen(testFileName.c_str(), "wt", stdout)) + __testlib_fail("Unable to write file '" + testFileName + "'"); +} + +inline std::string upperCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('a' <= s[i] && s[i] <= 'z') + s[i] = char(s[i] - 'a' + 'A'); + return s; +} + +inline std::string lowerCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('A' <= s[i] && s[i] <= 'Z') + s[i] = char(s[i] - 'A' + 'a'); + return s; +} + +inline std::string compress(const std::string &s) { + return __testlib_part(s); +} + +inline std::string englishEnding(int x) { + x %= 100; + if (x / 10 == 1) + return "th"; + if (x % 10 == 1) + return "st"; + if (x % 10 == 2) + return "nd"; + if (x % 10 == 3) + return "rd"; + return "th"; +} + +template +std::string join(_ForwardIterator first, _ForwardIterator last, _Separator separator) { + std::stringstream ss; + bool repeated = false; + for (_ForwardIterator i = first; i != last; i++) { + if (repeated) + ss << separator; + else + repeated = true; + ss << *i; + } + return ss.str(); +} + +template +std::string join(_ForwardIterator first, _ForwardIterator last) { + return join(first, last, ' '); +} + +template +std::string join(const _Collection &collection, _Separator separator) { + return join(collection.begin(), collection.end(), separator); +} + +template +std::string join(const _Collection &collection) { + return join(collection, ' '); +} + +/** + * Splits string s by character separator returning exactly k+1 items, + * where k is the number of separator occurences. + */ +std::vector split(const std::string &s, char separator) { + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == separator) { + result.push_back(item); + item = ""; + } else + item += s[i]; + result.push_back(item); + return result; +} + +/** + * Splits string s by character separators returning exactly k+1 items, + * where k is the number of separator occurences. + */ +std::vector split(const std::string &s, const std::string &separators) { + if (separators.empty()) + return std::vector(1, s); + + std::vector isSeparator(256); + for (size_t i = 0; i < separators.size(); i++) + isSeparator[(unsigned char) (separators[i])] = true; + + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (isSeparator[(unsigned char) (s[i])]) { + result.push_back(item); + item = ""; + } else + item += s[i]; + result.push_back(item); + return result; +} + +/** + * Splits string s by character separator returning non-empty items. + */ +std::vector tokenize(const std::string &s, char separator) { + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == separator) { + if (!item.empty()) + result.push_back(item); + item = ""; + } else + item += s[i]; + if (!item.empty()) + result.push_back(item); + return result; +} + +/** + * Splits string s by character separators returning non-empty items. + */ +std::vector tokenize(const std::string &s, const std::string &separators) { + if (separators.empty()) + return std::vector(1, s); + + std::vector isSeparator(256); + for (size_t i = 0; i < separators.size(); i++) + isSeparator[(unsigned char) (separators[i])] = true; + + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (isSeparator[(unsigned char) (s[i])]) { + if (!item.empty()) + result.push_back(item); + item = ""; + } else + item += s[i]; + + if (!item.empty()) + result.push_back(item); + + return result; +} + +NORETURN void __testlib_expectedButFound(TResult result, std::string expected, std::string found, const char *prepend) { + std::string message; + if (strlen(prepend) != 0) + message = format("%s: expected '%s', but found '%s'", + compress(prepend).c_str(), compress(expected).c_str(), compress(found).c_str()); + else + message = format("expected '%s', but found '%s'", + compress(expected).c_str(), compress(found).c_str()); + quit(result, message); +} + +NORETURN void __testlib_expectedButFound(TResult result, double expected, double found, const char *prepend) { + std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected)); + std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found)); + __testlib_expectedButFound(result, expectedString, foundString, prepend); +} + +template +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, T expected, T found, const char *prependFormat = "", ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + std::string expectedString = vtos(expected); + std::string foundString = vtos(found); + __testlib_expectedButFound(result, expectedString, foundString, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, std::string expected, std::string found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, expected, found, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, double expected, double found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected)); + std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found)); + __testlib_expectedButFound(result, expectedString, foundString, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, const char *expected, const char *found, const char *prependFormat, + ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, std::string(expected), std::string(found), prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, float expected, float found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, long double expected, long double found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +template +struct is_iterable { + template + static char test(typename U::iterator *x); + + template + static long test(U *x); + + static const bool value = sizeof(test(0)) == 1; +}; + +template +struct __testlib_enable_if { +}; + +template +struct __testlib_enable_if { + typedef T type; +}; + +template +typename __testlib_enable_if::value, void>::type __testlib_print_one(const T &t) { + std::cout << t; +} + +template +typename __testlib_enable_if::value, void>::type __testlib_print_one(const T &t) { + bool first = true; + for (typename T::const_iterator i = t.begin(); i != t.end(); i++) { + if (first) + first = false; + else + std::cout << " "; + std::cout << *i; + } +} + +template<> +typename __testlib_enable_if::value, void>::type +__testlib_print_one(const std::string &t) { + std::cout << t; +} + +template +void __println_range(A begin, B end) { + bool first = true; + for (B i = B(begin); i != end; i++) { + if (first) + first = false; + else + std::cout << " "; + __testlib_print_one(*i); + } + std::cout << std::endl; +} + +template +struct is_iterator { + static T makeT(); + + typedef void *twoptrs[2]; + + static twoptrs &test(...); + + template + static typename R::iterator_category *test(R); + + template + static void *test(R *); + + static const bool value = sizeof(test(makeT())) == sizeof(void *); +}; + +template +struct is_iterator::value>::type> { + static const bool value = false; +}; + +template +typename __testlib_enable_if::value, void>::type println(const A &a, const B &b) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << std::endl; +} + +template +typename __testlib_enable_if::value, void>::type println(const A &a, const B &b) { + __println_range(a, b); +} + +template +void println(const A *a, const A *b) { + __println_range(a, b); +} + +template<> +void println(const char *a, const char *b) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << std::endl; +} + +template +void println(const T &x) { + __testlib_print_one(x); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << " "; + __testlib_print_one(f); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f, const G &g) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << " "; + __testlib_print_one(f); + std::cout << " "; + __testlib_print_one(g); + std::cout << std::endl; +} + +/* opts */ + +/** + * A struct for a singular testlib opt, containing the raw string value, + * and a boolean value for marking whether the opt is used. + */ +struct TestlibOpt { + std::string value; + bool used; + + TestlibOpt() : value(), used(false) {} +}; + +/** + * Get the type of opt based on the number of `-` at the beginning and the + * _validity_ of the key name. + * + * A valid key name must start with an alphabetical character. + * + * Returns: 1 if s has one `-` at the beginning, that is, "-keyName". + * 2 if s has two `-` at the beginning, that is, "--keyName". + * 0 otherwise. That is, if s has no `-` at the beginning, or has more + * than 2 at the beginning ("---keyName", "----keyName", ...), or the + * keyName is invalid (the first character is not an alphabetical + * character). + */ +size_t getOptType(char *s) { + if (!s || strlen(s) <= 1) + return 0; + + if (s[0] == '-') { + if (isalpha(s[1])) + return 1; + else if (s[1] == '-') + return isalpha(s[2]) ? 2 : 0; + } + + return 0; +} + +/** + * Parse the opt at a given index, and put it into the opts maps. + * + * An opt can has the following form: + * 1) -keyName=value or --keyName=value (ex. -n=10 --test-count=20) + * 2) -keyName value or --keyName value (ex. -n 10 --test-count 20) + * 3) -kNumval or --kNumval (ex. -n10 --t20) + * 4) -boolProperty or --boolProperty (ex. -sorted --tree-only) + * + * Only the second form consumes 2 arguments. The other consumes only 1 + * argument. + * + * In the third form, the key is a single character, and after the key is the + * value. The value _should_ be a number. + * + * In the forth form, the value is true. + * + * Params: + * - argc and argv: the number of command line arguments and the command line + * arguments themselves. + * - index: the starting index of the opts. + * - opts: the map containing the resulting opt. + * + * Returns: the number of consumed arguments to parse the opt. + * 0 if there is no arguments to parse. + * + * Algorithm details: + * TODO. Please refer to the implementation to see how the code handles the 3rd and 4th forms separately. + */ +size_t parseOpt(size_t argc, char *argv[], size_t index, std::map &opts) { + if (index >= argc) + return 0; + + size_t type = getOptType(argv[index]), inc = 1; + if (type > 0) { + std::string key(argv[index] + type), val; + size_t sep = key.find('='); + if (sep != std::string::npos) { + val = key.substr(sep + 1); + key = key.substr(0, sep); + } else { + if (index + 1 < argc && getOptType(argv[index + 1]) == 0) { + val = argv[index + 1]; + inc = 2; + } else { + if (key.length() > 1 && isdigit(key[1])) { + val = key.substr(1); + key = key.substr(0, 1); + } else { + val = "true"; + } + } + } + opts[key].value = val; + } else { + return inc; + } + + return inc; +} + +/** + * Global list containing all the arguments in the order given in the command line. + */ +std::vector __testlib_argv; + +/** + * Global dictionary containing all the parsed opts. + */ +std::map __testlib_opts; + +/** + * Whether automatic no unused opts ensurement should be done. This flag will + * be turned on when `has_opt` or `opt(key, default_value)` is called. + * + * The automatic ensurement can be suppressed when + * __testlib_ensureNoUnusedOptsSuppressed is true. + */ +bool __testlib_ensureNoUnusedOptsFlag = false; + +/** + * Suppress no unused opts automatic ensurement. Can be set to true with + * `suppressEnsureNoUnusedOpts()`. + */ +bool __testlib_ensureNoUnusedOptsSuppressed = false; + +/** + * Parse command line arguments into opts. + * The results are stored into __testlib_argv and __testlib_opts. + */ +void prepareOpts(int argc, char *argv[]) { + if (argc <= 0) + __testlib_fail("Opts: expected argc>=0 but found " + toString(argc)); + size_t n = static_cast(argc); // NOLINT(hicpp-use-auto,modernize-use-auto) + __testlib_opts = std::map(); + for (size_t index = 1; index < n; index += parseOpt(n, argv, index, __testlib_opts)); + __testlib_argv = std::vector(n); + for (size_t index = 0; index < n; index++) + __testlib_argv[index] = argv[index]; +} + +/** + * An utility function to get the argument with a given index. This function + * also print a readable message when no arguments are found. + */ +std::string __testlib_indexToArgv(int index) { + if (index < 0 || index >= int(__testlib_argv.size())) + __testlib_fail("Opts: index '" + toString(index) + "' is out of range [0," + + toString(__testlib_argv.size()) + ")"); + return __testlib_argv[size_t(index)]; +} + +/** + * An utility function to get the opt with a given key . This function + * also print a readable message when no opts are found. + */ +std::string __testlib_keyToOpts(const std::string &key) { + auto it = __testlib_opts.find(key); + if (it == __testlib_opts.end()) + __testlib_fail("Opts: unknown key '" + compress(key) + "'"); + it->second.used = true; + return it->second.value; +} + +template +T optValueToIntegral(const std::string &s, bool nonnegative); + +long double optValueToLongDouble(const std::string &s); + +std::string parseExponentialOptValue(const std::string &s) { + size_t pos = std::string::npos; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == 'e' || s[i] == 'E') { + if (pos != std::string::npos) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + pos = i; + } + if (pos == std::string::npos) + return s; + std::string e = s.substr(pos + 1); + if (!e.empty() && e[0] == '+') + e = e.substr(1); + if (e.empty()) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + if (e.length() > 20) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + int ne = optValueToIntegral(e, false); + std::string num = s.substr(0, pos); + if (num.length() > 20) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + if (!num.empty() && num[0] == '+') + num = num.substr(1); + optValueToLongDouble(num); + bool minus = false; + if (num[0] == '-') { + minus = true; + num = num.substr(1); + } + for (int i = 0; i < +ne; i++) { + size_t sep = num.find('.'); + if (sep == std::string::npos) + num += '0'; + else { + if (sep + 1 == num.length()) + num[sep] = '0'; + else + std::swap(num[sep], num[sep + 1]); + } + } + for (int i = 0; i < -ne; i++) { + size_t sep = num.find('.'); + if (sep == std::string::npos) + num.insert(num.begin() + int(num.length()) - 1, '.'); + else { + if (sep == 0) + num.insert(num.begin() + 1, '0'); + else + std::swap(num[sep - 1], num[sep]); + } + } + while (!num.empty() && num[0] == '0') + num = num.substr(1); + while (num.find('.') != std::string::npos && num.back() == '0') + num = num.substr(0, num.length() - 1); + if (!num.empty() && num.back() == '.') + num = num.substr(0, num.length() - 1); + if ((!num.empty() && num[0] == '.') || num.empty()) + num.insert(num.begin(), '0'); + return (minus ? "-" : "") + num; +} + +template +T optValueToIntegral(const std::string &s_, bool nonnegative) { + std::string s(parseExponentialOptValue(s_)); + if (s.empty()) + __testlib_fail("Opts: expected integer but '" + compress(s_) + "' found"); + T value = 0; + long double about = 0.0; + signed char sign = +1; + size_t pos = 0; + if (s[pos] == '-') { + if (nonnegative) + __testlib_fail("Opts: expected non-negative integer but '" + compress(s_) + "' found"); + sign = -1; + pos++; + } + for (size_t i = pos; i < s.length(); i++) { + if (s[i] < '0' || s[i] > '9') + __testlib_fail("Opts: expected integer but '" + compress(s_) + "' found"); + value = value * 10 + s[i] - '0'; + about = about * 10 + s[i] - '0'; + } + value *= sign; + about *= sign; + if (fabsl(value - about) > 0.1) + __testlib_fail("Opts: integer overflow: expected integer but '" + compress(s_) + "' found"); + return value; +} + +long double optValueToLongDouble(const std::string &s_) { + std::string s(parseExponentialOptValue(s_)); + if (s.empty()) + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + long double value = 0.0; + signed char sign = +1; + size_t pos = 0; + if (s[pos] == '-') { + sign = -1; + pos++; + } + bool period = false; + long double mul = 1.0; + for (size_t i = pos; i < s.length(); i++) { + if (s[i] == '.') { + if (period) + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + else { + period = true; + continue; + } + } + if (period) + mul *= 10.0; + if (s[i] < '0' || s[i] > '9') + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + if (period) + value += (s[i] - '0') / mul; + else + value = value * 10 + s[i] - '0'; + } + value *= sign; + return value; +} + +/** + * Return true if there is an opt with a given key. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +bool has_opt(const std::string &key) { + __testlib_ensureNoUnusedOptsFlag = true; + return __testlib_opts.count(key) != 0; +} + +/* About the followings part for opt with 2 and 3 arguments. + * + * To parse the argv/opts correctly for a give type (integer, floating point or + * string), some meta programming must be done to determine the type of + * the type, and use the correct parsing function accordingly. + * + * The pseudo algorithm for determining the type of T and parse it accordingly + * is as follows: + * + * if (T is integral type) { + * if (T is unsigned) { + * parse the argv/opt as an **unsigned integer** of type T. + * } else { + * parse the argv/opt as an **signed integer** of type T. + * } else { + * if (T is floating point type) { + * parse the argv/opt as an **floating point** of type T. + * } else { + * // T should be std::string + * just the raw content of the argv/opts. + * } + * } + * + * To help with meta programming, some `opt` function with 2 or 3 arguments are + * defined. + * + * Opt with 3 arguments: T opt(true/false is_integral, true/false is_unsigned, index/key) + * + * + The first argument is for determining whether the type T is an integral + * type. That is, the result of std::is_integral() should be passed to + * this argument. When false, the type _should_ be either floating point or a + * std::string. + * + * + The second argument is for determining whether the signedness of the type + * T (if it is unsigned or signed). That is, the result of + * std::is_unsigned() should be passed to this argument. This argument can + * be ignored if the first one is false, because it only applies to integer. + * + * Opt with 2 arguments: T opt(true/false is_floating_point, index/key) + * + The first argument is for determining whether the type T is a floating + * point type. That is, the result of std::is_floating_point() should be + * passed to this argument. When false, the type _should_ be a std::string. + */ + +template +T opt(std::false_type is_floating_point, int index); + +template<> +std::string opt(std::false_type /*is_floating_point*/, int index) { + return __testlib_indexToArgv(index); +} + +template +T opt(std::true_type /*is_floating_point*/, int index) { + return T(optValueToLongDouble(__testlib_indexToArgv(index))); +} + +template +T opt(std::false_type /*is_integral*/, U /*is_unsigned*/, int index) { + return opt(std::is_floating_point(), index); +} + +template +T opt(std::true_type /*is_integral*/, std::false_type /*is_unsigned*/, int index) { + return optValueToIntegral(__testlib_indexToArgv(index), false); +} + +template +T opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, int index) { + return optValueToIntegral(__testlib_indexToArgv(index), true); +} + +template<> +bool opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, int index) { + std::string value = __testlib_indexToArgv(index); + if (value == "true" || value == "1") + return true; + if (value == "false" || value == "0") + return false; + __testlib_fail("Opts: opt by index '" + toString(index) + "': expected bool true/false or 0/1 but '" + + compress(value) + "' found"); +} + +/** + * Return the parsed argv by a given index. + */ +template +T opt(int index) { + return opt(std::is_integral(), std::is_unsigned(), index); +} + +/** + * Return the raw string value of an argv by a given index. + */ +std::string opt(int index) { + return opt(index); +} + +/** + * Return the parsed argv by a given index. If the index is bigger than + * the number of argv, return the given default_value. + */ +template +T opt(int index, const T &default_value) { + if (index >= int(__testlib_argv.size())) { + return default_value; + } + return opt(index); +} + +/** + * Return the raw string value of an argv by a given index. If the index is + * bigger than the number of argv, return the given default_value. + */ +std::string opt(int index, const std::string &default_value) { + return opt(index, default_value); +} + +template +T opt(std::false_type is_floating_point, const std::string &key); + +template<> +std::string opt(std::false_type /*is_floating_point*/, const std::string &key) { + return __testlib_keyToOpts(key); +} + +template +T opt(std::true_type /*is_integral*/, const std::string &key) { + return T(optValueToLongDouble(__testlib_keyToOpts(key))); +} + +template +T opt(std::false_type /*is_integral*/, U, const std::string &key) { + return opt(std::is_floating_point(), key); +} + +template +T opt(std::true_type /*is_integral*/, std::false_type /*is_unsigned*/, const std::string &key) { + return optValueToIntegral(__testlib_keyToOpts(key), false); +} + +template +T opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, const std::string &key) { + return optValueToIntegral(__testlib_keyToOpts(key), true); +} + +template<> +bool opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, const std::string &key) { + if (!has_opt(key)) + return false; + std::string value = __testlib_keyToOpts(key); + if (value == "true" || value == "1") + return true; + if (value == "false" || value == "0") + return false; + __testlib_fail("Opts: key '" + compress(key) + "': expected bool true/false or 0/1 but '" + + compress(value) + "' found"); +} + +/** + * Return the parsed opt by a given key. + */ +template +T opt(const std::string &key) { + return opt(std::is_integral(), std::is_unsigned(), key); +} + +/** + * Return the raw string value of an opt by a given key + */ +std::string opt(const std::string &key) { + return opt(key); +} + +/* Scorer started. */ + +enum TestResultVerdict { + SKIPPED, + OK, + WRONG_ANSWER, + RUNTIME_ERROR, + TIME_LIMIT_EXCEEDED, + IDLENESS_LIMIT_EXCEEDED, + MEMORY_LIMIT_EXCEEDED, + COMPILATION_ERROR, + CRASHED, + FAILED +}; + +std::string serializeVerdict(TestResultVerdict verdict) { + switch (verdict) { + case SKIPPED: return "SKIPPED"; + case OK: return "OK"; + case WRONG_ANSWER: return "WRONG_ANSWER"; + case RUNTIME_ERROR: return "RUNTIME_ERROR"; + case TIME_LIMIT_EXCEEDED: return "TIME_LIMIT_EXCEEDED"; + case IDLENESS_LIMIT_EXCEEDED: return "IDLENESS_LIMIT_EXCEEDED"; + case MEMORY_LIMIT_EXCEEDED: return "MEMORY_LIMIT_EXCEEDED"; + case COMPILATION_ERROR: return "COMPILATION_ERROR"; + case CRASHED: return "CRASHED"; + case FAILED: return "FAILED"; + } + throw "Unexpected verdict"; +} + +TestResultVerdict deserializeTestResultVerdict(std::string s) { + if (s == "SKIPPED") + return SKIPPED; + else if (s == "OK") + return OK; + else if (s == "WRONG_ANSWER") + return WRONG_ANSWER; + else if (s == "RUNTIME_ERROR") + return RUNTIME_ERROR; + else if (s == "TIME_LIMIT_EXCEEDED") + return TIME_LIMIT_EXCEEDED; + else if (s == "IDLENESS_LIMIT_EXCEEDED") + return IDLENESS_LIMIT_EXCEEDED; + else if (s == "MEMORY_LIMIT_EXCEEDED") + return MEMORY_LIMIT_EXCEEDED; + else if (s == "COMPILATION_ERROR") + return COMPILATION_ERROR; + else if (s == "CRASHED") + return CRASHED; + else if (s == "FAILED") + return FAILED; + ensuref(false, "Unexpected serialized TestResultVerdict"); + // No return actually. + return FAILED; +} + +struct TestResult { + int testIndex; + std::string testset; + std::string group; + TestResultVerdict verdict; + double points; + long long timeConsumed; + long long memoryConsumed; + std::string input; + std::string output; + std::string answer; + int exitCode; + std::string checkerComment; +}; + +std::string serializePoints(double points) { + if (std::isnan(points)) + return ""; + else { + char c[64]; + sprintf(c, "%.03lf", points); + return c; + } +} + +double deserializePoints(std::string s) { + if (s.empty()) + return std::numeric_limits::quiet_NaN(); + else { + double result; + ensuref(sscanf(s.c_str(), "%lf", &result) == 1, "Invalid serialized points"); + return result; + } +} + +std::string escapeTestResultString(std::string s) { + std::string result; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\r') + continue; + if (s[i] == '\n') { + result += "\\n"; + continue; + } + if (s[i] == '\\' || s[i] == ';') + result += '\\'; + result += s[i]; + } + return result; +} + +std::string unescapeTestResultString(std::string s) { + std::string result; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\\' && i + 1 < s.length()) { + if (s[i + 1] == 'n') { + result += '\n'; + i++; + continue; + } else if (s[i + 1] == ';' || s[i + 1] == '\\') { + result += s[i + 1]; + i++; + continue; + } + } + result += s[i]; + } + return result; +} + +std::string serializeTestResult(TestResult tr) { + std::string result; + result += std::to_string(tr.testIndex); + result += ";"; + result += escapeTestResultString(tr.testset); + result += ";"; + result += escapeTestResultString(tr.group); + result += ";"; + result += serializeVerdict(tr.verdict); + result += ";"; + result += serializePoints(tr.points); + result += ";"; + result += std::to_string(tr.timeConsumed); + result += ";"; + result += std::to_string(tr.memoryConsumed); + result += ";"; + result += escapeTestResultString(tr.input); + result += ";"; + result += escapeTestResultString(tr.output); + result += ";"; + result += escapeTestResultString(tr.answer); + result += ";"; + result += std::to_string(tr.exitCode); + result += ";"; + result += escapeTestResultString(tr.checkerComment); + return result; +} + +TestResult deserializeTestResult(std::string s) { + std::vector items; + std::string t; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\\') { + t += s[i]; + if (i + 1 < s.length()) + t += s[i + 1]; + i++; + continue; + } else { + if (s[i] == ';') { + items.push_back(t); + t = ""; + } else + t += s[i]; + } + } + items.push_back(t); + + ensuref(items.size() == 12, "Invalid TestResult serialization: expected exactly 12 items"); + + TestResult tr; + size_t pos = 0; + tr.testIndex = stoi(items[pos++]); + tr.testset = unescapeTestResultString(items[pos++]); + tr.group = unescapeTestResultString(items[pos++]); + tr.verdict = deserializeTestResultVerdict(items[pos++]); + tr.points = deserializePoints(items[pos++]); + tr.timeConsumed = stoll(items[pos++]); + tr.memoryConsumed = stoll(items[pos++]); + tr.input = unescapeTestResultString(items[pos++]); + tr.output = unescapeTestResultString(items[pos++]); + tr.answer = unescapeTestResultString(items[pos++]); + tr.exitCode = stoi(items[pos++]); + tr.checkerComment = unescapeTestResultString(items[pos++]); + + return tr; +} + +std::vector readTestResults(std::string fileName) { + std::ifstream stream; + stream.open(fileName.c_str(), std::ios::in); + ensuref(stream.is_open(), "Can't read test results file '%s'", fileName.c_str()); + std::vector result; + std::string line; + while (getline(stream, line)) + if (!line.empty()) + result.push_back(deserializeTestResult(line)); + stream.close(); + return result; +} + +std::function)> __testlib_scorer; + +struct TestlibScorerGuard { + ~TestlibScorerGuard() { + if (testlibMode == _scorer) { + std::vector testResults; + while (!inf.eof()) { + std::string line = inf.readLine(); + if (!line.empty()) + testResults.push_back(deserializeTestResult(line)); + } + inf.readEof(); + printf("%.3f\n", __testlib_scorer(testResults)); + } + } +} __testlib_scorer_guard; + +void registerScorer(int argc, char *argv[], std::function)> scorer) { + /* Supress unused. */ + (void)(argc), (void)(argv); + + __testlib_ensuresPreconditions(); + + testlibMode = _scorer; + __testlib_set_binary(stdin); + + inf.init(stdin, _input); + inf.strict = false; + + __testlib_scorer = scorer; +} + +/* Scorer ended. */ + +/** + * Return the parsed opt by a given key. If no opts with the given key are + * found, return the given default_value. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +template +T opt(const std::string &key, const T &default_value) { + if (!has_opt(key)) { + return default_value; + } + return opt(key); +} + +/** + * Return the raw string value of an opt by a given key. If no opts with the + * given key are found, return the given default_value. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +std::string opt(const std::string &key, const std::string &default_value) { + return opt(key, default_value); +} + +/** + * Check if all opts are used. If not, __testlib_fail is called. + * Should be used after calling all opt() function calls. + * + * This function is useful when opt() with default_value for checking typos + * in the opt's key. + */ +void ensureNoUnusedOpts() { + for (const auto &opt: __testlib_opts) { + if (!opt.second.used) { + __testlib_fail(format("Opts: unused key '%s'", compress(opt.first).c_str())); + } + } +} + +void suppressEnsureNoUnusedOpts() { + __testlib_ensureNoUnusedOptsSuppressed = true; +} + +void TestlibFinalizeGuard::autoEnsureNoUnusedOpts() { + if (__testlib_ensureNoUnusedOptsFlag && !__testlib_ensureNoUnusedOptsSuppressed) { + ensureNoUnusedOpts(); + } +} + +TestlibFinalizeGuard testlibFinalizeGuard; + +#endif +#endif diff --git a/rede-anel-estelar/src/validator.cpp b/rede-anel-estelar/src/validator.cpp new file mode 100644 index 0000000..07c8e90 --- /dev/null +++ b/rede-anel-estelar/src/validator.cpp @@ -0,0 +1,39 @@ +#include "testlib.h" +#include + +using namespace std; + +const int MIN_N = 1; +const int MAX_N = 100; + +int main(int argc, char* argv[]) { + registerValidation(argc, argv); + + int n = inf.readInt(MIN_N, MAX_N, "n"); + inf.readSpace(); + + int max_possible_edges = (n * (n - 1)) / 2; + int m = inf.readInt(0, max_possible_edges, "m"); + inf.readEoln(); + + set> existing_edges; + + for (int i = 0; i < m; i++) { + int u = inf.readInt(1, n, "u"); + inf.readSpace(); + int v = inf.readInt(1, n, "v"); + inf.readEoln(); + + ensuref(u != v, "self-loops are not allowed. vertice %d has a connection with it-self", u); + + pair edge = {min(u, v), max(u, v)}; + + ensuref(existing_edges.find(edge) == existing_edges.end(), "edge between %d and %d already exists", u, v); + + existing_edges.insert(edge); + } + + inf.readEof(); + + return 0; +} \ No newline at end of file diff --git a/rede-anel-estelar/statement/description.tex b/rede-anel-estelar/statement/description.tex new file mode 100644 index 0000000..a62e612 --- /dev/null +++ b/rede-anel-estelar/statement/description.tex @@ -0,0 +1,17 @@ +A Agência Espacial de Algoritmia está implementando uma nova infraestrutura de comunicação global baseada em criptografia quântica. +Para garantir a estabilidade do sistema, a arquitetura da rede deve seguir um padrão de topologia muito estrito, denominado \textbf{Rede Anel-Estelar Conexa}. + +O monitoramento da rede gerou um relatório contendo a topologia atualizada do sistema, representada por um grafo não direcionado com \( n \) roteadores quânticos, e \( m \) canais de fibra ótica. + +Os engenheiros de rede precisam determinar se a topologia atual atende perfeitamente às especificações de uma Rede Anel-Estelar Conexa. + +Formalmente, uma topologia é considerada válida se o grafo puder ser decomposto em um \textbf{conjunto de três ou mais árvores enraizadas, cujas raízes estão interconectadas por um único ciclo simples}, formando uma única componente conexa. +O ciclo simples representa o anel de sincronização principal, \textit{backbone}, e as árvores representam as sub-redes locais de distribuição que se ramificam a partir dos nós principais. + +É garantido que o grafo não contém canais redundantes, isso é, mais de uma conexão entre um mesmo par de roteadores, e nem conexões de um roteador consigo mesmo. + +\begin{figure}[h] + \centering + \includegraphics[width=0.7\textwidth]{image.png} + \caption{Exemplo da topologia de uma Rede Anel-Estelar Conexa, com os roteadores que compõem o \textit{backbone} em amarelo.} +\end{figure} \ No newline at end of file diff --git a/rede-anel-estelar/statement/input.tex b/rede-anel-estelar/statement/input.tex new file mode 100644 index 0000000..1268504 --- /dev/null +++ b/rede-anel-estelar/statement/input.tex @@ -0,0 +1,5 @@ +A primeira linha contém dois inteiros: \( n \) (\( 1 \le n \le 100 \)), representando o número de vértices, e \( m \) (\( 0 \le m \le \frac{n(n-1)}{2} \)), representando o número de arestas do grafo. + +Cada uma das \( m \) linhas seguintes contém um par de inteiros \( x \) e \( y \) (\( 1 \le x, y \le n \), \( x \neq y \)), indicando que existe uma aresta conectando os vértices \( x \) e \( y \). + +É garantido que para cada par de vértices haverá no máximo uma única aresta ligando-os e nenhuma aresta conecta um vértice a si mesmo. \ No newline at end of file diff --git a/rede-anel-estelar/statement/notes.tex b/rede-anel-estelar/statement/notes.tex new file mode 100644 index 0000000..6fde7f7 --- /dev/null +++ b/rede-anel-estelar/statement/notes.tex @@ -0,0 +1 @@ +Problema adaptado de \href{https://codeforces.com/problemset/problem/104/C}{Codeforces Beta Round 80 (Div. 2 Only, Problem C)}. \ No newline at end of file diff --git a/rede-anel-estelar/statement/output.tex b/rede-anel-estelar/statement/output.tex new file mode 100644 index 0000000..54cdbe2 --- /dev/null +++ b/rede-anel-estelar/statement/output.tex @@ -0,0 +1,3 @@ +Se a topologia atual corresponder perfeitamente às especificações de uma Rede Estrela-Anel Conexa, imprima o código de validação do sistema: \texttt{ONLINE}. + +Caso contrário, imprima \texttt{OFFLINE}. \ No newline at end of file diff --git a/rede-anel-estelar/statement/preamble.tex b/rede-anel-estelar/statement/preamble.tex new file mode 100644 index 0000000..e69de29 diff --git a/rede-anel-estelar/statement/tutorial.tex b/rede-anel-estelar/statement/tutorial.tex new file mode 100644 index 0000000..6d3bb9a --- /dev/null +++ b/rede-anel-estelar/statement/tutorial.tex @@ -0,0 +1,9 @@ +A verificação desta topologia de rede exige validar se a estrutura possui exatamente um anel central (ciclo simples) com tamanho mínimo de 3 nós, onde cada nó do anel distribui sinal para uma sub-rede sem ciclos (árvore). + +Em termos de teoria dos grafos, para que um grafo não direcionado finito represente exatamente essa arquitetura, ele deve satisfazer simultaneamente dois critérios fundamentais: +\begin{itemize} + \item A rede deve ser totalmente \textbf{conexa}, ou seja, deve ser possível enviar dados de qualquer roteador para qualquer outro roteador da rede (nenhuma sub-rede pode estar isolada). + \item O número total de roteadores deve ser \textbf{exatamente igual} ao número total de canais ativos (\( n = m \)). +\end{itemize} + +Se o grafo possuir \( n = m \), for totalmente conexo e tiver \( n \ge 3 \), ele terá estruturalmente apenas um ciclo simples com árvores acopladas a ele, o que valida o sistema com a saída \texttt{ONLINE}. Caso contrário, a topologia é inválida e a resposta será \texttt{NO}. \ No newline at end of file