{"uid":"cap_PwPpcv5_np_-qGW7443xQ","slug":"graph-algorithms-floyd-warshall-all-pairs-shortest-distances-277825e3","name":"Graph Algorithms: Floyd-Warshall All-Pairs Shortest Distances","description":"Floyd-Warshall all-pairs shortest distances for up to 100 nodes; negative weights ok; detects negative cycles.","url":"https://graph-algorithms.x402tookit.com/all-pairs-shortest?utm_source=zero.xyz","method":"GET","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","method"],"properties":{"type":{"type":"string","const":"http"},"method":{"enum":["GET"],"type":"string"},"queryParams":{"type":"object","required":["edges"],"properties":{"to":{"type":"string","description":"Optional node: with 'from', also returns that shortest path"},"from":{"type":"string","description":"Optional node: with 'to', also returns that shortest path"},"edges":{"type":"string","description":"Edges separated by ; or newline, each 'from,to' or 'from,to,weight' (default weight 1), or a JSON array of [from,to,weight]; up to 100 nodes for this endpoint, 1000 edges, 60000 characters; node names 1-32 characters of letters, digits, _ . : + -"},"nodes":{"type":"string","description":"Optional extra node names (comma or space separated) so isolated nodes are counted; the total still counts toward the 200-node cap"},"directed":{"type":"boolean","description":"true (default); false makes each edge two-way (a negative edge then is a negative cycle)"}}}},"additionalProperties":false},"output":{"type":"object","required":["type"],"properties":{"type":{"type":"string"},"example":{"type":"object","properties":{"asOf":{"type":["null","string"]},"path":{"type":["array","null"],"items":{"type":"string"}},"order":{"type":["array","null"],"items":{"type":"string"}},"source":{"type":["null","string"]},"reasons":{"type":["array","null"]},"summary":{"type":["null","string"]},"verdict":{"type":["null","string"]},"degraded":{"type":["boolean","null"]},"directed":{"type":["boolean","null"]},"distances":{"type":["array","null"],"items":{"type":"array","items":{"type":"number"}}},"edgeCount":{"type":["null","number"]},"nodeCount":{"type":["null","number"]},"disclaimer":{"type":["null","string"]},"notChecked":{"type":["array","null"],"items":{"type":"string"}},"pathDistance":{"type":["null","number"]},"reachablePairs":{"type":["null","number"]},"unreachablePairs":{"type":["null","number"]}}}}}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.03","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.03/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.03","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.03","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_nJ-fzfRxhCbp9M7fE2bI7","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.03","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Computes all-pairs shortest distances for a weighted directed or undirected graph of up to 100 nodes using Floyd-Warshall, detecting negative cycles.","exampleAgentPrompt":"Find the shortest distances between all pairs of nodes in this directed graph — edges: A,B,2; B,C,-1; A,C,4; C,D,3 — and also give me the shortest path from A to D.","exampleUseCases":[{"title":"Network latency routing analysis","prompt":"I have a network with 6 routers and measured latencies between them as edges: router1,router2,5; router2,router3,3; router1,router3,10; router3,router4,2; router2,router4,8; router4,router5,1; router5,router6,4 — can you compute the all-pairs shortest latency distances so I know the best routes between every pair?"},{"title":"Detecting negative cycles in a financial graph","prompt":"I have a currency arbitrage graph where edges represent log-exchange-rate gains: USD,EUR,-0.05; EUR,GBP,-0.03; GBP,USD,-0.01; EUR,JPY,0.1; JPY,USD,-0.12 — run all-pairs shortest paths on it and tell me if there's a negative cycle I could exploit."},{"title":"Dependency graph distance between tasks","prompt":"I have a project task dependency graph with weighted effort costs: design,backend,3; design,frontend,2; backend,testing,1; frontend,testing,1; testing,deploy,2; backend,deploy,5 — give me the all-pairs shortest distances and the shortest path from design to deploy."}],"resultDescription":"Returns a full distance matrix (2D array of shortest distances between all node-pairs), a sorted node order array, node count, edge count, reachable pairs count, a flag indicating if the graph is directed, and optionally the shortest path and distance between a specified source and target node. If a negative cycle is detected, returns a verdict and reasons describing it.","failureModes":["Graph exceeds 100 nodes — endpoint only supports up to 100 nodes","Edge list exceeds 1000 edges or 60000 characters — request rejected","Node name contains disallowed characters (must be letters, digits, _ . : + - and 1-32 chars long)","Malformed edge format — edges must be 'from,to' or 'from,to,weight' separated by ; or newline or valid JSON array","Negative cycle detected — distances become undefined; endpoint reports the cycle instead of a full distance matrix","Missing required 'edges' query parameter — request will fail","Undirected graph with a negative edge will always be a negative cycle — verdict returned immediately"],"whenToPreferThis":"Use this endpoint when you need shortest distances between ALL pairs of nodes simultaneously (not just from a single source), especially when the graph may contain negative edge weights. Prefer this over Dijkstra (single-source, no negative weights) or Bellman-Ford (single-source) when you need the complete O(n²) distance matrix in one call. Ideal for small-to-medium graphs up to 100 nodes. If the graph is a DAG and you only need ordering, prefer the topological sort endpoint instead.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-11-02T12:30:33.556Z","isFirstParty":false,"canonicalSlug":"graph-algorithms-floyd-warshall-all-pairs-shortest-distances-277825e3"}