#include
#include
#define SWAP(x,y,t) ((t)=(x),(x)=(y),(y)=(t))
int repeat=0;
int spotAmount=0;
int wayAmount=0;
int destAmount=0;
int ptFrom[4950]={};
int ptTo[4950]={};
int weight[4950]={};
int destPt[4950]={};
int temp=0;
typedef struct stor
{
int sum;
int step;
int dir[4950];
}stor;
typedef struct link //연결리스트 사용
{
stor memoPt;
struct link* next;
}link;
link* startLink=NULL;
link* lastLink=NULL;
int storAmount=0;
int partition(int list[],int left,int right) //퀵정렬
{
int pivot,temp;
int low,high;
low=left;
high=right+1;
pivot=list[left];
do{
do
{
low+=1;
}while(low<=right&&list[low]
do
{
high-=1;
}while(high>=left&&list[high]>pivot);
if(low<high)
{
SWAP(list[low],list[high],temp);
SWAP(ptTo[low],ptTo[high],temp);
SWAP(weight[low],weight[high],temp);
}
}while(low<high);
SWAP(list[left],list[high],temp);
SWAP(ptTo[left],ptTo[high],temp);
SWAP(weight[left],weight[high],temp);
return high;
}
void quick_sort(int list[],int left,int right) //퀵정렬
{
if(left<right)
{
int q=partition(list,left,right);
quick_sort(list,left,q-1);
quick_sort(list,q+1,right);
}
}
GilDong
http://algospot.com/judge/problem/read/AVOID
~~~ c++
#include
#include
#define SWAP(x,y,t) ((t)=(x),(x)=(y),(y)=(t))
int repeat=0;
int spotAmount=0;
int wayAmount=0;
int destAmount=0;
int ptFrom[4950]={};
int ptTo[4950]={};
int weight[4950]={};
int destPt[4950]={};
int temp=0;
typedef struct stor
{
int sum;
int step;
int dir[4950];
}stor;
typedef struct link //연결리스트 사용
{
stor memoPt;
struct link* next;
}link;
link* startLink=NULL;
link* lastLink=NULL;
int storAmount=0;
int partition(int list[],int left,int right) //퀵정렬
do
{
int pivot,temp;
int low,high;
low=left;
high=right+1;
pivot=list[left];
do{
do
{
low+=1;
}while(low<=right&&list[low]
{
high-=1;
}while(high>=left&&list[high]>pivot);
if(low<high)
{
SWAP(list[low],list[high],temp);
SWAP(ptTo[low],ptTo[high],temp);
SWAP(weight[low],weight[high],temp);
}
}while(low<high);
SWAP(list[left],list[high],temp);
SWAP(ptTo[left],ptTo[high],temp);
SWAP(weight[left],weight[high],temp);
return high;
}
void quick_sort(int list[],int left,int right) //퀵정렬
{
if(left<right)
{
int q=partition(list,left,right);
quick_sort(list,left,q-1);
quick_sort(list,q+1,right);
}
}
void func(int curNum,int loopNum,long long sum,stor memo) //재귀함수
{
break;
{
{
if(curNum==ptTo[wayAmount-1])
{
memo.dir[memo.step++]=curNum;
memo.sum=sum;
link* newLink=(link*)malloc(sizeof(link)); //메모리 할당하는 부분!!
newLink->memoPt=memo;
newLink->next=NULL;
if(storAmount==0)
{
startLink=newLink;
lastLink=newLink;
}
else
{
lastLink->next=newLink;
lastLink=newLink;
}
storAmount++;
return;
}
for(int i=loopNum+1;i
if(curNum==ptFrom[i])
{
stor tempMemo=memo;
tempMemo.dir[(tempMemo.step)++]=curNum;
func(ptTo[i],i,sum+weight[i],tempMemo);
continue;
}
else if(curNum
}
}
int main()
{
long long allWay=0;
long long findNum=0;
scanf("%d",&repeat);
while(repeat--)
{
startLink=NULL;
lastLink=NULL;
storAmount=0;
spotAmount=wayAmount=destAmount=0;
scanf("%d %d %d",&spotAmount,&wayAmount,&destAmount);
for(int i=0;i
scanf("%d %d %d",&ptFrom[i],&ptTo[i],&weight[i]);
if(ptFrom[i]>ptTo[i])
{
temp=ptTo[i];
ptTo[i]=ptFrom[i];
ptFrom[i]=temp;
}
}
for(int i=0;i<destAmount;i++)
scanf("%d",&destPt[i]);
}
12년 전