ko_osaga's blog

By ko_osaga, history, 4 years ago, In English

Hello! I'm happy to announce XXI Open Cup. Grand Prix of Suwon. Gyeonggi Science High School is located in Suwon, Korea.

This contest was used as a Day 9 Contest from Petrozavodsk Winter 2021 Camp.

List of relevant previous contests:

Enjoy!

Full text and comments »

  • Vote: I like it
  • +155
  • Vote: I do not like it

By ko_osaga, history, 4 years ago, In English

Hi!

Tomorrow at 22:00 KST I will stream solving New Year Prime Contest 2021. It is an ongoing contest, but Prime Contest is special, so I think it's okay to stream.

My goal is to implement the task "Gardening Game". Worteltje said it is very interesting. Let's give it a try!

If I have time left, I will try to implement "Evacuation" with SMAWK.

The stream will end if Prime Contest 2021 ends.

See you!

Full text and comments »

  • Vote: I like it
  • +226
  • Vote: I do not like it

By ko_osaga, history, 4 years ago, In English

Hi! Tomorrow at 21:00 KST I will stream solving judge.yosupo.jp. In the stream, I will try to implement Edmond's Directed MST algorithm with this lecture note.

I will solve the following problems in the stream. Recommendations are welcome, preferably ones that's not just "Find Directed MST".

Since this is not a regular data structure stream, I will keep it short. The stream will last about 3 hours.

This event isn't that well-prepared like others, please don't expect too much :)

Thanks!

Full text and comments »

  • Vote: I like it
  • +117
  • Vote: I do not like it

By ko_osaga, history, 4 years ago, In English

Hello! I'm happy to announce XXI Open Cup. Grand Prix of Korea.

Special thanks to xiaowuc1 for revising our English.

List of relevant previous contests:

Enjoy!

Full text and comments »

  • Vote: I like it
  • +279
  • Vote: I do not like it

By ko_osaga, history, 4 years ago, In English

Thanks to vintage_Vlad_Makeev for the information.

According to Wikipedia, RP is a class of decision problem which admits a randomized polynomial-time algorithm such that:

  • If the correct answer is NO, it always returns NO
  • If the correct answer is YES, then it returns YES with probability at least 1/2 (otherwise, it returns NO).

The Amazing Power of Randomness: NP=RP authored by Andras Farago claims that NP=RP. This means, there is a randomized polynomial time solution to NP problems, such as:

  • 3-SAT
  • Traveling Salesperson Problem
  • Minimum Vertex Cover
  • Graph Coloring
  • Among others

What does it mean? Is the paper wrong? Should we start studying randomized algorithm instead of machine learning? Will all cryptographic system collapse?

Share your thoughts!

Full text and comments »

  • Vote: I like it
  • +769
  • Vote: I do not like it

By ko_osaga, history, 5 years ago, In English

Currently, Jury archives for NERC 2019 is missing, unlike the other years.

Can anyone look into those issues and update the website?

Full text and comments »

  • Vote: I like it
  • +35
  • Vote: I do not like it

By ko_osaga, history, 5 years ago, In English

In 2020/05/24 14:00 KST, I will stream solving 全国統一プログラミング王決定戦本戦.

I'll also experiment with my new tablets, so there will be some explanation of my thinking process.

Even if you can't read Japanese, don't worry. I can't read it either, and I'll have a hard time with the translator too.

The stream will end if I solve everything or if it's too late.

Stream link is https://www.twitch.tv/gs14004 as usual.

See you!

Full text and comments »

  • Vote: I like it
  • +33
  • Vote: I do not like it

By ko_osaga, history, 5 years ago, In English

I uploaded 2020 Petrozavodsk Winter Camp, Jagiellonian U Contest to the CF Gym.

The problemset was used in 2020 Petrozavodsk Winter Camp, and North America Programming Camp 2020. Both ghosts are in scoreboard, so it's a good opportunity to test your skills.

In the version used in PtzCamp and NAPC, problem K had a weak test and the model solution failed in my simple handcrafted tests. I just added that test, and changed the problem limit leniently to allow model solution to pass. I guess this made the problem much easier now.

Thanks to the problemsetters (I don't know who are them). Enjoy!

Editorial

Full text and comments »

  • Vote: I like it
  • +77
  • Vote: I do not like it

By ko_osaga, history, 5 years ago, In English

You are given a graph $$$G$$$, and for each vertex $$$v$$$ you have to assign a positive integer color such that every adjacent pair of vertices (vertices directly connected by edge) have different color assigned. You have to minimize the maximum color assigned: In other words, you have to minimize the number of distinct assigned colors.

But that's graph coloring (vertex coloring). It's hard. Ok, one more time:

You are given a graph $$$G$$$, and for each edge $$$e$$$ you have to assign a positive integer color such that every adjacent pair of edges (edges sharing same endpoints) have different color assigned. You have to minimize the maximum color assigned: In other words, you have to minimize the number of distinct assigned colors.

This is the edge coloring of graph, and I will talk about this now.

Note that this can be interpreted as "graph coloring (vertex coloring) of line graphs". In that sense, you can consider in a similar spirit to "graph coloring of interval graphs", "graph coloring of permutation graphs", blah-blah.

General graph

Let $$$D = max_{v \in V(G)}deg(v)$$$ be the maximum degree of a graph. Since every vertex should be incident to edges with different colors, the edges can't be colored with less than $$$D$$$ colors.

So if we somehow find the way to color the edges with $$$D$$$ colors, the case is closed. This is obviously not true: Consider a 3-cycle, then $$$D = 2$$$, but you need 3 colors.

Still, Vizing discovered that this is approximately true:

  • Theorem (Vizing, 1964). Every simple graph can be edge-colored with $$$D+1$$$ colors.
  • Proof: If you are interested then see here.

Note that:

  • Theorem doesn't hold if the graph has multiple edges connecting same vertices.
  • It's NP-hard to determine if the graph can be colored with $$$D$$$ colors, so optimal coloring is still NP-hard.

Wikipedia discusses the $$$O(nm)$$$ algorithm to find a $$$D+1$$$ edge coloring of simple graph, which you can find the implementation here. Sometimes, people asks you to solve just that exact same problem, and sometimes you can just cheese problems without thinking too much. Anyway, this is not our main point. let's jump to more interesting part.

Bipartite Graphs

To find an optimal edge coloring, we have to prove that the edges can be colored with $$$D$$$ colors. In general graph this was a little (one color!) bit of fail, but as the countercase had an odd cycle, maybe in bipartite graph this is true?

  • Theorem. Every bipartite graph can be edge-colored with $$$D$$$ colors.

  • Proof. We use induction on $$$D$$$.

  • If $$$D = 0$$$, the proposition is trivial.

  • Otherwise, we will partition the graph $$$G$$$ with a matching $$$M$$$ and a graph $$$G\setminus M$$$ with maximum degree $$$D - 1$$$. We transform the graph $$$G$$$ in such a way that the left/right bipartition have equal number of vertices (just add dummy nodes of degree 0), and every node have degree $$$D$$$ (repeatedly pick two nodes with degree $$$<D$$$ and add a dummy edge. If this procedure fails, then two bipartition have different sum of degrees, which is impossible).

    Let $$$L, R$$$ be a bipartition of this new graph. Now we assume every node of $$$G$$$ have degree $$$D$$$. Suppose there is no perfect matching in $$$G$$$. Then by Hall's theorem, there exists a subset of vertices $$$S \subseteq L$$$ such that $$$|N(S)| < |S|$$$. Then there exists $$$|S| \times D$$$ edges connecting between $$$N(S)$$$ and $$$S$$$. On the other hand, there can't exist more than $$$|N(S)| \times D$$$ edges incident to $$$N(S)$$$. Contradiction. Thus the perfect matching exists.

    Now remove the dummy edges from the perfect matching. Note that the dummy edges don't connect any node which originally had degree $$$D$$$. So the edges left from the matching still covers all nodes with degree $$$D$$$. Denote this matching $$$M$$$. Then $$$G \setminus M$$$ have maximum degree $$$D - 1$$$. Color the edges in $$$M$$$ with color $$$D$$$, and color $$$G \setminus M$$$ by inductive hypothesis.

  • Remark. Theorem still holds when the graph has multiple edges.

This also gives an algorithm to find a edge coloring of bipartite graphs. We just want to find any matching that covers all nodes with maximum degree $$$D$$$. If all nodes have degree $$$D$$$, then simple bipartite matching works. In general case, since we have to cover some nodes, we have to model this as flow and enforce some edges to have capacity 1. This can be modeled with maximum flow with demands. In any case, if you use Dinic's algorithm or Hopcroft/Karp, time complexity is $$$O(D \times MN^{0.5})$$$.

So that's great, we can optimally solve edge coloring of bipartite graph in polynomial time. On the other hand, using matching or even flow with demands is pretty tiring and complicated, can we get rid of flows at all?

There is an implementation of edge coloring in $$$O(NM)$$$ with short code and good constant factor, which doesn't rely on flow argument. You can read about this algorithm here (problem F). Here is the implementation I use, which is copied from waterfalls' submission here.

Faster

Can we do this faster? Let's go back to Dinic's algorithm. Here's a simple yet elegant trick to reduce the time complexity from $$$O(D \times MN^{0.5})$$$ to $$$O(MN^{0.5} \log D)$$$.

The idea is, as you can guess from the $$$\log$$$ factor, divide-and-conquer. If $$$D$$$ is odd, you can just use the naive method to reduce the degree to $$$D - 1$$$. If $$$D$$$ is even, it partitions the graph into two pieces with maximum degree $$$\frac{D}{2}$$$. But how?

Let's revisit the following well-known fact related to even degrees:

  • Lemma (Euler Circuit). For connected graphs where every node has even degree, there is a circuit which visits every edges exactly once.

And also, there exists an algorithm to compute the Euler circuits in linear time.

So now, let's add some dummy edges again to connect the vertices with odd degree. Obviously, there exists even number of vertices with odd degree, so we can add any kind of matchings between them. Now, every connected component has an Euler circuit, so we can compute them for linear time.

Now, note that the Euler circuit obviously have even length in bipartite graphs, let's denote the circuit as $$$C = {e_1, e_2, \ldots, e_{2k}}$$$. Let's color the odd-numbered edges ($$$e_1, e_3, e_5 \ldots$$$) as blue, and even-numbered edges as red. Then, for each vertex $$$v$$$, we can see it is adjacent to $$$\frac{deg(v)}{2}$$$ blue nodes and $$$\frac{deg(v)}{2}$$$ red nodes! This is because, if the circuit entered the vertex with some color, it leaves the vertex with different colors.

Thus, just take the Euler circuit for each component, and divide the edges into blue and red sets. Remove dummy edges, and you still have max degree $$$\frac{D}{2}$$$ for each color. So you can recurse from that point! Since every edges are considered at at most $$$O(\log D)$$$ recursion stage, and they contribute to at most $$$N^{0.5}$$$ overhead, the time complexity is $$$O(MN^{0.5} \log D)$$$.

More faster!!

Now let's look for something genuinely fast: Fast enough that it doesn't involve any flow and have $$$O(M\log M \log D)$$$ solution!

Going back to the original proof, we know that it is easier to assume that the graph is regular: Every node has degree of $$$D$$$. Naive strategy of adding edges, as described in proof, adds too much edges and is inefficient. But we can improve it by "merging" small-degree nodes: If two node have sum of degree at most $$$D$$$, then we can merge(contract) two nodes, and any coloring in this new graph still works in the original one.

So, for each side of biparitition, while there is at least 2 nodes with $$$deg(v) \le \frac{D}{2}$$$, find them and contract it. After the end of this procedure, we are left with at most 2 nodes (one for each bipartition) with $$$deg(v) \le \frac{D}{2}$$$. Now, even if we apply the naive way of adding dummy nodes and edges, we end up adding at most $$$O(cM)$$$ edges where $$$c \le 3$$$ in my naive calculation.

Now let's assume the graph is regular. Thanks to regularity, we don't have to find flows anymore but can simply calculate a perfect matching in this regular graph. It doesn't look easy to find this faster than $$$O(M^{1.5})$$$, but there is an algorithm to compute a perfect matching of regular graph in $$$O(M \log M)$$$, which was discovered in 2010: https://arxiv.org/pdf/0909.3346.pdf

To briefly explain what's going on, the algorithm is actually not very different from finding a bipartite matching with flows. We construct a usual flow graph with source and sinks, and find an augmenting path. There are just two notable difference:

  • If the edge is in matching, rather than reversing it, we just contract two endpoint of such edge. You can see this doesn't make the situation different.
  • We don't use DFS to find path: We use random walk from source, which means we will sample any outgoing edges with random probability, and halt until it reaches the sink.

Intuitively, the second heuristic will run very fast in the initial stage of augmenting path finding. At the first stage the length of path will be length 3, and it will remain so until a certain period. Random walk procedure is much faster than DFS in such case, because it's time complexity is just it's walk length. Now, the paper claims the following:

  • Lemma 6 (from paper). If we found $$$m < n$$$ matchings in a current graph, then the expected number of steps taken by the random walk is at most $$$2 + \frac{n}{n - m}$$$.

Then, we can simply do this for all $$$0 \le m \le n - 1$$$, and get $$$2n + n \sum_{i=1}^{n}\frac{1}{i} = O(n \log n)$$$!

Lastly, note that this problem can be solved in $$$O(M \log M)$$$ time. Interested readers can find it in the second reference link.

Challenge

The $$$O(mn)$$$ algorithm is very simple to implement and it usually don't find long Kempe chains. I doubt that is true for any fast algorithm I mentioned. Plus, it won't be cache oblivious. Can anyone implement any $$$o(mn)$$$ algorithm for bipartite edge coloring which runs faster than $$$O(mn)$$$ algorithm?

Practice problem

I added some practice problem for this topic. Some of them are directly related to my article, some of them checks your creativity at reducing different problems to bipartite edge coloring.

References

Also special thanks to 300iq for introducing me the paper for perfect matching.

Full text and comments »

  • Vote: I like it
  • +361
  • Vote: I do not like it

By ko_osaga, history, 5 years ago, In English

From Sunday 14:00 UTC-4 Eastern Daylight Time, I will stream solving problems in Chinese OJ. Specifically, I'll try to

  • Read these two papers (paper1 paper2) and try to learn them
  • Write it in Chinese OJ (problem1 problem2). Huge thanks to TLE for making this stream more authentic.

Stream link is https://www.twitch.tv/gs14004. Stream will be in English.

I'm not sure about the exact plan, but I'll stream at least 4 hours.

See you!

Full text and comments »

  • Vote: I like it
  • +151
  • Vote: I do not like it

By ko_osaga, 5 years ago, In English

About 4 hours later (2020/01/27 20:30 KST), I will stream solving random OI problems.

Things I might try solving:

The stream will end if I get sleepy.

Stream link is https://www.twitch.tv/gs14004 as usual.

See you!

Full text and comments »

  • Vote: I like it
  • +39
  • Vote: I do not like it

By ko_osaga, history, 5 years ago, In English

Since the Polygon tutorial system is currently broken, I will replace the editorial with PDF format. Sorry for the inconvenience!

Solution PDF

Problem A was authored by ko_osaga. Code

Problem B was authored by ko_osaga. Code

Problem C was authored by ko_osaga. Code

Problem D was authored by nong. Code

Problem E was authored by ckw1140. Code

Problem F was authored by ko_osaga. Code

Problem G was authored by ko_osaga. Code

Full text and comments »

Tutorial of Hello 2020
  • Vote: I like it
  • +191
  • Vote: I do not like it

By ko_osaga, 5 years ago, In English

새해 복 많이 받으세요, 코드포스! (Happy new year, Codeforces!)

Welcome to the first Codeforces Round of the new decade, Hello 2020! The round will be held on Jan/04/2020 15:05 MSK.

Some information about the round:

  • Div 1, 2 combined
  • 2.5 hours!
  • 7 problems!
  • No subtasks!
  • Score distribution: 500-1250-1750-2500-2750-4000-4000
  • Yes, it is rated!

This round is prepared by ko_osaga nong ckw1140. I am personally very thrilled to deliver my first Codeforces contest as such a memorable one!

More credits for the contest:

UPD: Editorial. Thank you for your participation!

UPD2: Winners:

  1. mnbvmar
  2. TLE
  3. Benq
  4. tourist
  5. gamegame
  6. never_giveup
  7. dario2994
  8. yosupo
  9. Marcin_smu
  10. kczno1

Full text and comments »

Announcement of Hello 2020
  • Vote: I like it
  • +1231
  • Vote: I do not like it

By ko_osaga, history, 5 years ago, In English

From Friday 14:00 UTC+9 Korea Standard Time, I will stream solving problems in Baekjoon OJ. All problems will be only about doing some queries on sequences or graphs.

Stream link is https://www.twitch.tv/gs14004.

My goal is to stream until Saturday 0:00 (10 hours), including meals and some other breaks.

See you!

Full text and comments »

  • Vote: I like it
  • +141
  • Vote: I do not like it

By ko_osaga, history, 5 years ago, In English

Hi! In Korea Regional ICPC homepage, news about ICPC East Asia Pacific Semifinal has appeared. I didn't found any other articles about this, so I'll upload this to get some contribution.

There will be a semi-final competition in the East Asia-Pacific region between the Regional Contest and the World Final. The official title is undecided, but the semifinals will be held in Vietnam on December 21-23, 2020. Up to this year, we are selecting teams to advance to the world competitions, but starting next year, some will be selected at the regional competitions and some will be selected at the semifinals. Unlike the World Championships, the semifinals are expected to allow multiple teams, with an upper limit on the number of teams in each university. The East Asia-Pacific region includes Korea, Taiwan, Japan, Southeast Asia such as Vietnam, the Philippines and Indonesia, and Oceania such as Australia and New Zealand.

Original post

Great to see some fair team selection in East Asia!

Full text and comments »

  • Vote: I like it
  • +67
  • Vote: I do not like it

By ko_osaga, history, 5 years ago, In English

Update 2019/11/07. The contest is now in Gym. Thanks to MikeMirzayanov for uploading it. Have fun!

Hello! I'm happy to announce XX Open Cup. Grand Prix of Korea.

List of relevant previous contests:

Enjoy!

Full text and comments »

  • Vote: I like it
  • +161
  • Vote: I do not like it

By ko_osaga, history, 5 years ago, In English

From Friday 14:00 UTC+9 Korea Standard Time, I will stream solving ICPC World Finals 2018 J, Uncrossed Knight's Tour.

Stream link is https://www.twitch.tv/gs14004. Sorry for changing it from my previous account (I'm somehow unable to login with my previous account. I think it is hacked.)

I'll stream until I solve it, or I give up and sleep.

See you!

Full text and comments »

  • Vote: I like it
  • +85
  • Vote: I do not like it

By ko_osaga, history, 5 years ago, In English

Hello!

International Olympiad in Informatics (IOI), the most prestigious programming contest in the world, is held in a beautiful city of Baku, Azerbaijan this year.

Wish the best luck to every contestant!

Day1: The contest had started on time, but the scoreboard is broken. It seems there is no mirror this year.

Day1 Contest Overview: Benq solved all Day1 problems in only 3.5 hours, congratulations! Full scorers for each tasks: 23(rect) / 170(shoes) / 6(split)

Day2 Contest Overview: The winner for Day2 is duality, but Benq still secures his consecutive IOI win. Congratulations! Full scorers for each tasks: 0(line) / 47(vision) / 2(walk)

Contest Results

  1. Benq 547.09
  2. 300iq 511.22
  3. duality 494.33
  4. TLE 491.46
  5. FizzyDavid 482.39

Country Ranking

  • 1 Russia 4G
  • 2 China 3G1S
  • 2 United States of America 3G1S
  • 4 Republic of Korea 2G1S1B
  • 4 Vietnam 2G1S1B

Congratulations to everyone who competed, and especially to our super awesome team gina0605 GyojunYoun Onjo blackbori !

Useful Links:

Full text and comments »

Tags ioi
  • Vote: I like it
  • +195
  • Vote: I do not like it

By ko_osaga, history, 5 years ago, In English

If there are any errors, please write it in the comment.

Rank CF Handle
1 Radewoosh Poland
2 ACRush China
3 Errichto Poland
4 _h_ Sweden
5 vintage_Vlad_Makeev Russia
6 molamola. South Korea
7 ksun48 Canada
8 tourist Belarus
9 majk Czechia
10 qwerty787788 Ukraine
11 ecnerwala United States
12 Marcin_smu Poland
13 zemen Russia
14 vepifanov Russia
15 yutaka1999 Japan
16 Um_nik Russia
17 Petr Russia
18 PavelKunyavskiy Russia
19 xyz111 China
20 ko_osaga South Korea
21 jqdai0815 China
22 ainta South Korea
23 maroonrk Japan
24 LHiC Russia
25 aid Russia

Full text and comments »

Tags fhc
  • Vote: I like it
  • +105
  • Vote: I do not like it

By ko_osaga, history, 5 years ago, In English

Hi all!

Did you know that SRM 763 is scheduled in 15:00 July 17, 2019 UTC+0? I didn't, and I bet you also didn't, so here is a helpful reminder.

Let's wait for hmehta to announce the writers.

And, don't forget the TCO19 Round 3B!

Full text and comments »

  • Vote: I like it
  • +53
  • Vote: I do not like it

By ko_osaga, history, 6 years ago, In English

Hi! I was migrating KAIST RUN Spring Contest 2019 into CF Gym, and encountered following error:

For problem C, E, I made a copy of the original problem, as Gym system can't interpret test groups. Otherwise, they are all sane. They are packaged with verification, and user codeforces has write rights for all problems.

I believe this is beyond my scope to handle, MikeMirzayanov, could you please help?

Full text and comments »

  • Vote: I like it
  • +28
  • Vote: I do not like it

By ko_osaga, history, 6 years ago, In English

Update 2019/06/12: Me and MikeMirzayanov managed to upload the Div.2 contest into Gym. Huge thanks him for the great system, and also a kind help!

However, I decided not to just open it, but to give a training contest. The contest is scheduled in June 14 Friday, 09:00 UTC. Even considering some obvious bias from the setter, I'm personally very proud of the Div.2 contest :D I hope you participate and share the same joy with us! (and of course, please don't cheat!)

.

.

.

.

.

.

.

.

Update 2019/06/05: I managed to upload the Div.1 contest into Gym. Have fun! https://codeforces.net/gym/102201

Open Cup GP of Daejeon is scheduled at 2019/05/05 Sunday, 11:00 MSK. Daejeon is a city where KAIST is.

Division 1 problem set is identical with MIPT PreFinals Camp 2019 Day 6. It was held on March 15.

Division 2 problem set is identical with KAIST RUN Spring Contest 2019. It was held on May 1 locally. Like last year, it was an IOI-style contest, but as we are doing in OpenCup, subtask will be disabled. Some problems between Div1 and Div2 are shared.

Problems were created by ainta, Konijntje, ko_osaga, kriii, kdh9949. Some problems in Div1 were borrowed by Diuven, imeimi.

Problems were tested by arknave, dotorya, Namnamseo, tzuyu_chou, .o..

List of relevant previous contests:

Enjoy!

Full text and comments »

  • Vote: I like it
  • +88
  • Vote: I do not like it

By ko_osaga, history, 6 years ago, In English

To jump on a bandwagon, I'll run a boring stream, where I'll virtual participate JOI Spring Camp 2019 Day2 (or Day1 if that's harder). The time will be 3/21 Thursday 7:30 PM UTC+9 (KST)

https://www.twitch.tv/koosaga

If this works out well, I'll maybe continue streaming after WF. I'll try to solve problems that is both hard and annoying, something like this.

See you!

Full text and comments »

  • Vote: I like it
  • +58
  • Vote: I do not like it

By ko_osaga, history, 6 years ago, In English

Hmm.. Am I the only one not appearing in the scoreboard?!?

Full text and comments »

  • Vote: I like it
  • +67
  • Vote: I do not like it

By ko_osaga, history, 6 years ago, In English
  • Vote: I like it
  • +49
  • Vote: I do not like it