I have points, I need to check the collisions between them, the solution was to put all of them in a graph, the distance between the points will be the weight. When adding, you need to somehow check that the edge already exists, how to do it correctly, someone can have an example in any C of such a language.
Found something like this:

vector<int> graph[100000]; //массив из 100000 векторов. int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--, v--; graph[u].push_back(v); graph[v].push_back(u); } for (int i = 0; i < n; i++) { int c = 0; for (int v: graph[i]) { c++; } cout << c << " edges adjacent to vertex " << i + 1 << endl; } } 

Did so without a graph:

 namespace Helper { export class CollisionContainer { public container: Entities.GameEntity[] = []; public add(entity: Entities.GameEntity) { this.getLength(entity); this.container.push(entity); } public reset(){ this.container = []; } public getLength(entity: Entities.GameEntity) { this.container.forEach((item: Entities.GameEntity)=> { let length = entity.position.getLengthToPoint(item.position); if (item.radius + entity.radius > length) { item.onCollision(entity); entity.onCollision(item); } }); } } } 
  • one
    And what is the problem? there is a graph, if there is an edge with two nodes, then it is - Grundy
  • The answer is likely to depend on the specific way in which you keep this very graph. If like a list of edges is one thing, if like an adjacency matrix is ​​another ... - Yaant
  • @Yaant, yes, it seems the same, that it’s like that :) - Grundy
  • @Yaant adjacency lists - Serge Esmanovich 1:51 pm
  • @Grundy, well, checking the value of an element in a two-dimensional array, knowing both indices, will still be somehow simpler than finding the desired element in a possibly unsorted list of pairs of vertices. :) - Yaant 1:54 pm

0