Codeforces и Polygon могут быть недоступны в период с 6 декабря, 22:00 (МСК) по 7 декабря, 00:00 (МСК) в связи с проведением технических работ. ×

Блог пользователя bugbuster404

Автор bugbuster404, история, 3 года назад, По-английски

I have been trying this for a long time but still getting WA on test 22 (onwards)

Problem

Basically you are given an undirected graph consisting of n vertices and m edges where every edge has weight=1. The distance between two vertices is equal to the minimum possible number of edges on a path between them.

There are given two vertices S and T . You have to select two vertices u and v (where u and v don't have a direct edge) such that joining them DOES NOT decrease the distance between S and T. We have to print how many such distinct unordered pairs exist...

...

I ran BFS two times and found the shortest distance of every vertices from S and T and used the following relation to find whether u and v should be added or not:-

if ((distance_s[u] + distance_t[v] + 1 < distance_s[t]) || (distance_s[v] + distance_t[u] + 1 < distance_s[t]))

Here is the entire code :-

Spoiler

Everytime I am getting WA on test 22. Its calculating less than the actual value. Plz help which cases I am missing

Thx :)

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Nevermind about the last edit, I read your code wrong. You can check my code if you'd like, using an adjacency matrix was way more practical. https://mirror.codeforces.com/contest/954/submission/135211021