#include "garden.h"
#include "gardenlib.h"
#include "iostream"
#include "vector"
#include "map"
#include "math.h"
#include "string"
#include "algorithm"
#include "set"
#include <iterator>
#include <string.h>
#include <queue>
#include <list>
using namespace std;
typedef long long ll ;
const ll M = 998244353 ;
const ll oo = 1e13 ;
set<pair<int , int>> v[150010] ;
map<int , ll> mp ;
int cost[100010];
void bfs(int p){
queue<int> q;
q.push(p);
cost[p] = 0 ;
mp[0]++;
while(q.size()){
int u = q.front();
q.pop();
for(auto x : v[u]){
if(cost[x.second] != -1)
continue ;
q.push(x.second);
cost[x.second] = cost[u] + 1;
if(v[x.second].size() == 1)
cost[x.second]++;
mp[cost[x.second]]++;
if(u != p)
break;
}
}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
memset(cost , -1 , sizeof cost);
for(int i = 0 ; i < M ; ++i){
v[R[i][1]].insert({i , R[i][0]});
v[R[i][0]].insert({i , R[i][1]});
}
bfs(P);
for(int i = 0 ; i < Q ; i++){
answer(mp[G[i]]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
7772 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
7772 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
7772 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |