Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long int
- ll mod = 1000000007;
- ll ans = 2;
- void bfs(vector<vector<ll>> &adj,int k)
- {
- int n = adj.size()-1;
- vector<bool> vis(n+1,false);
- queue<ll> q;
- q.push(1);
- unordered_map<ll,ll> m;
- vis[1] = true;
- while(!q.empty())
- {
- int curr = q.front();
- q.pop();
- for(int x:adj[curr])
- {
- if(vis[x])
- continue;
- m[x] = m[curr] + 1;
- vis[x] = true;
- q.push(x);
- if(m[x]>=k)
- continue;
- ans = (ans*2ll)%mod;
- }
- }
- }
- int Solution::solve(vector<vector<int> > &edge, int k) {
- int n = edge.size()+1;
- vector<vector<ll>> adj(n+1);
- for(vector<int> v:edge)
- {
- adj[v[0]].push_back(v[1]);
- adj[v[1]].push_back(v[0]);
- }
- bfs(adj,k);
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement