Skip to main content
  1. Blog/

Installing atcoder library

·221 words·2 mins
aryanc403
Author
aryanc403
Asia West Champion, ICPC World Finals 2021 | CodeChef Snackdown, World Finalist 2021
Table of Contents

Atcoder library official documentation

Setup (One time steps)
#

First clone atcoder library in your preferred path.

git clone https://github.com/atcoder/ac-library.git $HOME/atcoder-library

Add atcoder library to your standard library path.

echo export CPLUS_INCLUDE_PATH=\"\$HOME/atcoder-library:\$CPLUS_INCLUDE_PATH\" >> $HOME/.bashrc
If you zsh

Use the following command if you use bash instead of zsh.

echo export CPLUS_INCLUDE_PATH=\"\$HOME/atcoder-library:\$CPLUS_INCLUDE_PATH\" >> $HOME/.zshrc

Adding support for submitting on other platforms

echo alias fullexpand=\"python3 \$HOME/atcoder-library/expander.py\" >> $HOME/.bashrc
If you zsh

Use the following command if you use bash instead of zsh.

echo alias fullexpand=\"python3 \$HOME/atcoder-library/expander.py\" >> $HOME/.zshrc

Testing
#

Lets solve Unionfind from Library Checker using the library.

Paste the following code in your favourite text editor.

#include <atcoder/dsu>
#include <cstdio>

using namespace std;
using namespace atcoder;

int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    dsu d(n);
    for (int i = 0; i < q; i++) {
        int t, u, v;
        scanf("%d %d %d", &t, &u, &v);
        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
                printf("1\n");
            } else {
                printf("0\n");
            }
        }
    }
    return 0;
}

Run the following command on terminal to paste contents of dsu instead of import path

fullexpand <filename>

E.g. -

fullexpand a.cpp

A new file with name combined.cpp will be created in the same folder. Submit it on online judges.

Epilogue
#

Congrats you have successfully installed atcoder library.