Try using Python's networkx with AtCoder

Networkx available in AtCoder

With the language update of AtCoder, Python became 3.8 series, but networkx can be used. Considering the processing time, I think that the cases to use are limited, but I will introduce it because I tried it.

You can check the version of each library by entering the following in the code test of AtCoder. networkx contains 2.4.

import sys
print("python", sys.version)
import numpy as np
print("numpy", np.__version__)
import scipy as sp
print("scipy", sp.__version__)
import networkx as nx
print("networkx", nx.__version__)
import sklearn
print("sklearn", sklearn.__version__)
python 3.8.2 (default, Feb 26 2020, 02:56:10) 
[GCC 7.4.0]
numpy 1.18.2
scipy 1.4.1
networkx 2.4
sklearn 0.22.2.post1

Try to solve the problem with networkx

For example, try C problem of ACL Beginner Contest. The answer is the number of connected components -1 because it is a matter of the number of edges required to connect all the networks. For networkx, use number_connected_components.

import networkx as nx
G = nx.Graph()
n, m = map(int, input().split())
G.add_nodes_from(range(n))
for i in range(m):
    a, b = map(int, input().split())
    G.add_edge(a-1, b-1)
print(nx.number_connected_components(G) - 1)

I did AC, but the execution time and memory are terrible. This seems to be usable only for problems with considerable margin. image.png

Recommended Posts

Try using Python's networkx with AtCoder
Try using the camera with Python's OpenCV
Try using Python's feedparser.
Try using Python's Tkinter
Try using PythonTex with Texpad.
Try using matplotlib with PyCharm
Try using folium with anaconda
Try mining Bitcoin with Python's hashlib
Try mathematical formulas using Σ with python
Try using Dropbox API v2 with Go
Try using Python with Google Cloud Functions
Try using Tkinter
Try using docker-py
Try using cookiecutter
Try using PDFMiner
Try using geopandas
Try using Selenium
Try using scipy
Try using pandas.DataFrame
Try using django-swiftbrowser
Try using tf.metrics
Try using PyODE
Try using conda virtual environment with Jupyter Notebook
Getting Started with Python's ast Module (Using NodeVisitor)
Try drawing a map with Python's folium package
Try scraping with Python.
Solve AtCoder 167 with python
Try to dynamically create a Checkbutton with Python's Tkinter
Try projective transformation of images using OpenCV with Python
Try using virtualenv (virtualenvwrapper)
Try to make RESTful API with MVC using Flask 1.0.2
[Azure] Try using Azure Functions
Try using W & B
Try SNN with BindsNET
Try using Django templates.html
[Kaggle] Try using LGBM
Try using Tweepy [Python2.7]
Try using Pytorch's collate_fn
Getting Started with python3 # 3 Try Advanced Computations Using Import Statements
Try MD simulation with ANN potential using aenet and ASE
Things to keep in mind when using Python with AtCoder
Try encryption / decryption using OpenSSL key with Python3 pow function
Try to implement linear regression using Pytorch with Google Colaboratory
Using X11 with ubuntu18.04 (C)
Try to factorial with recursion
When using optparse with iPython
Try deep learning with TensorFlow
Solve AtCoder ABC166 with python
Use directional graphs with networkx
Light blue with AtCoder @Python
Using Graphviz with Jupyter Notebook
Face recognition with Python's OpenCV
Draw a graph with NetworkX
Try using Jupyter's Docker image
Messaging with AMQP using kombu
Try using scikit-learn (1) --K-means clustering
Try implementing RBM with chainer.
Implement subcommands with Python's argparse
Try function optimization using Hyperopt
In-graph path search using Networkx
Try Google Mock with C