# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
96756 | mohammad | 열대 식물원 (Tropical Garden) (IOI11_garden) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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++){
int mx = 0;
for(int j = 1 ; j < M ; ++j){
if(G[i] % j == 0)
mx = max(mx , mp[G[i]]);
}
answer(mx);
}
}