PAT甲级 1003
来源:互联网 发布:750x254淘宝店招素材 编辑:程序博客网 时间:2024/06/05 20:12
#include <iostream>#include <stdlib.h>#include <stdio.h>#define ElementType int#define MaxVertexNum 501#define INFINITY 1000000using namespace std;typedef struct GNode *PtrToGNode;struct GNode{ int Nv; int Ne; ElementType G[MaxVertexNum][MaxVertexNum];};typedef PtrToGNode MGraph;void DFS(int v,int end,int len,int pnum,MGraph Graph);int visitDFS[501]={0};int people[501]={0};int cnt=0,num=0;int n,m,c1,c2;int minlen=INFINITY,templen=0;int main() { // insert code here... MGraph Graph = (MGraph)malloc(sizeof(struct GNode)); //init Graph->Nv=0; Graph->Ne=0; for (int i=0; i<MaxVertexNum; i++) { for (int j=0; j<MaxVertexNum; j++) { Graph->G[i][j] = INFINITY; } } cin>>n>>m>>c1>>c2; Graph->Nv = n; Graph->Ne = m; for (int i=0; i<n; i++) { cin>>people[i]; } for (int i=0; i<Graph->Ne; i++) { int row,col,len; scanf("%d %d %d",&row,&col,&len); Graph->G[row][col]=len; Graph->G[col][row]=len; } DFS(c1,c2,0,people[c1], Graph); cout<<cnt<<" "<<num; return 0;}void DFS(int v,int end,int len,int pnum,MGraph Graph){ if (v==end) { if (minlen == len) { cnt++; if (num<pnum) { num = pnum; } } if (minlen>len) { minlen = len; cnt=1; num = pnum; //printf("debug:minlen =%d\n ",minlen); } return; } if (len>minlen) { return; } visitDFS[v]=1; for (int i = 0; i<Graph->Nv; i++) { if (Graph->G[v][i]!=INFINITY&&!visitDFS[i]) { DFS(i,end,len+Graph->G[v][i], pnum+people[i], Graph); } } visitDFS[v]=0;}
阅读全文
0 0
- PAT(甲级)1003
- PAT甲级1003
- PAT-甲级-1003
- PAT甲级1003
- PAT甲级1003
- PAT甲级1003
- pat 甲级 1003 Emergency
- 浙大PAT甲级-1003
- PAT甲级 1003
- 【PAT】甲级1003
- PAT甲级练习题1003
- PAT甲级 1003
- PAT 甲级
- PAT 甲级 1003Emergency(Dijkstra最短路)
- pat甲级_路径问题(例题:pat 1003 Emergency (25))
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1004
- FortiGate-50E、FortiWiFi-50E、FortiGate/FortiWiFi-51E和FortiGate-52E
- STM32--ADC(DMA)
- Android Bitmap使用
- 此数据库没有有效所有者,因此无法安装数据库关系图支持对象。
- Python 3.6 生成器
- PAT甲级 1003
- iOS Category的正确理解
- C++孤子
- 图像的边缘检测
- 剑指offer算法题之二维数组查找(一步一步优化)
- CSS引入外部字体文件
- tomcat 配置 https 用keytools
- 斑马打印机打印图片
- redis学习系列(十)--redis-集群安装