#include<bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,tes,t,L[300009],LL[300009],P,K,pas,bo[300009],msh[300009],MSH[300009],msh2[300009],MSH2[300009],dis[300009];
vector <int> v[300009];
vector <pair <int, int> > VP[300009];
deque <int> de;
void count_routes(int NN, int MM, int PP, int RR[][2], int QQ, int GG[])
{
a=NN;b=MM;P=PP+1;tes=QQ;
for(i=1; i<=a; i++){
L[i]=b+5;
}
for(i=1; i<=b; i++){
c=RR[i-1][0]+1;d=RR[i-1][1]+1;
VP[c].push_back({i,d});
VP[d].push_back({i,c});
if(L[c]==b+5){
L[c]=i;LL[c]=d;
}
if(L[d]==b+5){
L[d]=i;LL[d]=c;
}
}
for(i=1; i<=a; i++){
sort(VP[i].begin(),VP[i].end());
msh[i]=VP[i][0].second;MSH[i]=VP[i][0].first;
if(VP[i].size()==1){
msh2[i]=VP[i][0].second;MSH2[i]=VP[i][0].first;
}else{
msh2[i]=VP[i][1].second;MSH2[i]=VP[i][1].first;
}
}
for(i=1; i<=a; i++){
ii=0;
if(L[msh[i]]!=MSH[i]){
j=msh[i];jj=0;
}else{
j=msh[i];jj=1;
}
v[j*2+jj].push_back(i*2+ii);
ii=1;
if(L[msh2[i]]!=MSH2[i]){
j=msh2[i];jj=0;
}else{
j=msh2[i];jj=1;
}
v[j*2+jj].push_back(i*2+ii);
}
for(t=1; t<=tes; t++){
K=GG[t-1];pas=0;
while(de.size()!=0) de.pop_back();
for(i=0; i<=a*2+3; i++){
bo[i]=0;dis[i]=K+2;
}
dis[P*2]=dis[P*2+1]=0;
de.push_back(P*2);de.push_back(P*2+1);
while(de.size()){
while(de.size()&&bo[de.front()]!=0){
de.pop_front();
}
bo[de.front()]=1;
c=de.front();de.pop_front();
if(dis[c]>K) break;
if(dis[c]==K){
if(c%2==0){
pas++;
}
}
for(vector <int>::iterator it=v[c].begin(); it!=v[c].end(); it++){
if(bo[(*it)]==1) continue;
if(dis[(*it)]>dis[c]+1){
dis[(*it)]=dis[c]+1;
de.push_back((*it));
}
}
}
answer(pas);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
14548 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
14548 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
14548 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |