Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int MAX = 21001;
- int best;
- vector < int > myVector[MAX];
- bitset < MAX > beenThere;
- queue < int > myQueue;
- int D[MAX];
- int T,N,M;
- inline void Read()
- {
- scanf("%d%d", &N , &M);
- for ( int i = 1; i <= M ; ++i)
- {
- int x,y;
- scanf("%d%d", &x , &y);
- myVector[x].push_back(y);
- myVector[y].push_back(x);
- }
- }
- inline int BFS(int currentNode)
- {
- myQueue.push(currentNode);
- beenThere[currentNode] = true;
- best = 0;
- while(!myQueue.empty())
- {
- int node = myQueue.front();
- myQueue.pop();
- for ( auto &neighbor : myVector[node])
- {
- //int neighbor = myVector[node][k];
- if(!beenThere[neighbor])
- {
- myQueue.push(neighbor);
- beenThere[neighbor] = true;
- D[neighbor] = D[node]+1;
- best = D[neighbor];
- }
- }
- }
- return best;
- }
- int main()
- {
- freopen("amici2.in" , "r" , stdin);
- freopen("amici2.out" , "w" ,stdout);
- scanf("%d", &T);
- for ( int i = 1 ; i <= T ; ++i)
- {
- for ( int j = 1; j <= N ; ++j)
- myVector[j].clear();
- beenThere.reset();
- Read();
- int Answer = ceil(log2(BFS(1)));
- printf("%d\n" , Answer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement