Skip to main content

Graph Input Visualizer & Converter

Paste raw graph data from Codeforces, LeetCode, or ICPC. We automatically detect the format, visualize it instantly, and convert it to other representations.

Advertisement

Input Data
Nodes: 0 Edges: 0

Advertisement

See the Graph Shape Before Writing a Single Line of DFS

In Codeforces, AtCoder, LeetCode, and ICPC problems, graph inputs arrive as plain integer tables: a line count N M followed by edge pairs, a square matrix of zeros and weights, or a parent array for a tree. Staring at twelve lines of numbers rarely tells you whether the sample case contains a cycle, two disconnected components, or a long chain. Sketching nodes by hand on scrap paper works until weights or fifteen vertices turn the page into spaghetti.

Paste your raw sample input into this visualizer and it detects the format, draws an interactive physics canvas where you can drag nodes apart, switches between Force Directed and Hierarchical Tree layouts, converts the graph into four text representations, and exports a PNG image directly in your browser.

Six Input Formats (and How Auto Detect Chooses)

You can load built in samples from the Examples dropdown or paste straight from a problem statement. Auto Detect inspects your lines using these rules:

Format Expected Syntax Parsing Behavior
Edge List 4 5 then u v per line Automatically skips line 1 if it has 1 or 2 tokens (N or N M) and multiple lines exist
Weighted Edge List 4 4 then u v w per line Reads the third token as the numeric edge weight and renders labels on edges
Adjacency Matrix N rows of N numbers Creates 0 indexed nodes 0..N-1; nonzero values draw weighted edges
Parent Array Single line: 1 1 2 2 1 indexed children pointing from parent[i] to i+1; ignores 0, -1, and self loops
Adjacency List 1: 2 4 per line Each line starts with node: followed by space or comma separated neighbors
Entity to Items List n, then k v1 v2... Row i (1 indexed) declares degree k followed by k target nodes

Watch one small heuristic quirk in Edge List mode: if your entire graph consists of a single edge pair on line one (for example, 1 2 with no N M header) and you add another line later, line one is treated as a header whenever multiple lines exist and line one has two tokens or fewer. If you paste an edge list without an N M header row where every line is an edge, checking the canvas confirms immediately whether line one was skipped, or you can simply include N M on top like standard contest test cases.

Force Directed vs Tree Layouts and Directed Deduplication

General graphs with cycles, dense cliques, or bipartite clusters look clearest under Force Directed Layout, which simulates spring physics across edges and repulsion between vertices so clusters pull apart naturally. Drag any node with your mouse to untangle overlapping edges, or hit Center to zoom the whole graph cleanly back into frame.

When inspecting rooted trees, dependency DAGs, or Parent Array inputs, switch the layout dropdown to Hierarchical (Tree). That locks physics off and arranges nodes top to bottom by directed hierarchy. Remember to check the Directed toggle when working with DAGs, topological sorting, or asymmetric adjacency matrices: turning Directed off deduplicates mirror pairs like 1: 2 and 2: 1 (or symmetric matrix entries M[i][j] and M[j][i]) so undirected graphs show one clean line instead of duplicate stacked curves.

Why Isolated Vertices Vanish From Edge Lists (and How to Keep Them)

Suppose a problem states 5 3 (5 vertices, 3 edges) and edges 1 2, 2 3, 3 1, leaving vertices 4 and 5 completely isolated. Because Edge List mode only inspects actual edge rows after skipping the N M header line, vertices 4 and 5 never appear in any edge pair and will not appear on the canvas.

Whenever you need isolated zero degree nodes visible on screen (for example when checking connected component counts in Union Find or BFS), represent the input using one of the formats that declares every vertex row explicitly: an Adjacency List with empty rows (4: and 5:), an Adjacency Matrix with all zero rows, or an Entity to Items List with 0 on those rows.

Converting Graph Formats and Saving Diagrams

Click Convert in the toolbar to reformat the active graph into any of four outputs without writing throwaway conversion scripts:

  • Adjacency List: Outputs node: neighbor1 neighbor2 lines (appending weights like 2(10) when weighted), respecting your Directed toggle so undirected edges mirror automatically into both nodes' lists.
  • Adjacency Matrix: Builds a space separated V x V matrix filled with 0 for missing edges and 1 (or edge weight) for active connections.
  • Edge List: Flattens matrices or adjacency lists back into clean u v or u v w lines.
  • JSON: Exports the parsed { nodes, edges, isDirected, isWeighted, type } object for quick pasting into JavaScript tests or visualizer prototypes.

Need to embed a clean diagram in lecture slides, README docs, or a problem editorial? Click Save PNG to download the live canvas rendering as BlackClaaw_Graph.png.

Network Graph FAQs

What input formats does the visualizer accept?

The tool accepts space separated edge lists (u v or u v w), 2D square adjacency matrices, single line parent arrays, adjacency lists (node: neighbors), and entity to items lists (k v1 v2...).

Can I toggle between directed and undirected graphs?

Yes. Flipping the Directed switch immediately updates arrowheads on the canvas and controls whether symmetric matrix or adjacency list entries are deduplicated as undirected edges or kept separate.

How many nodes can the interactive visualizer render smoothly?

Canvas physics runs smoothly up to a few hundred nodes and edges in modern desktop browsers. Very large graphs with thousands of edges become visually crowded and slow down force simulation, so switch to Hierarchical Tree layout or test smaller subgraphs when debugging.

Does the tool support weighted edges?

Yes. Three tokens per line (u v weight) in edge lists, or nonzero values inside an adjacency matrix, display numeric weights directly along each edge.

Is my problem data or code stored anywhere?

No. Input parsing, physics layout, format conversion, and PNG export run completely inside your browser tab.

Related Developer Tools