| 记录编号 |
57979 |
评测结果 |
AAWWWWWWWW |
| 题目名称 |
1349.计划 |
最终得分 |
20 |
| 用户昵称 |
digital-T |
是否通过 |
未通过 |
| 代码语言 |
C++ |
运行时间 |
0.009 s |
| 提交时间 |
2013-04-15 15:27:24 |
内存使用 |
2.97 MiB |
显示代码纯文本
#include<fstream>
#include<algorithm>
#include<vector>
using namespace std;
ifstream fi("plan.in");
ofstream fo("plan.out");
vector <int> point[1001];//链表存图
class bb
{
public:
int v;//顶点序号
double w;
};
vector <bb> pp;//可开发区域
bool boo[1001],dry[1001]={false};
int n,m,k,eachm[1001];//each-m是每点的剩余m值
void outofhere(int x,int y,double z)//伸展x节点,剩余干粮y,可能性为z
{
//fo<<x<<' '<<y<<endl;
if(point[x].size()==0)//x可开发
{
bb how;
how.v=x;
how.w=z;
if(y<0)how.w=0;
pp.push_back(how);
}
else//x可以拓展
{
int B=point[x].size();
for(int ii=0;ii<=B-1;ii++)//point[x][ii]是x出发可到达节点
{
if(point[point[x][ii]].size()!=0&&dry[point[x][ii]])outofhere(point[x][ii],y-2,z/B);
else outofhere(point[x][ii],y-1,z/B);
}
}
}
bool op(bb left,bb right)
{
if(left.w==right.w)//相同可能性
if(left.v>right.v)return 0;
else return 1;
if(left.w>right.w)return 0;
return 1;
}
int main()
{
fi>>n>>m>>k;
int i,j,p,q;
for(i=1;i<=k;i++)fi>>j,dry[j]=true;
for(i=1;i<=n-1;i++)
{
fi>>p>>q;
point[p].push_back(q);
}
outofhere(1,m,100);//伸展吧!
sort(pp.begin(),pp.end(),op);
j=pp.size()-1;
fo<<pp[0].v<<endl;
while(pp[j].w==pp[j-1].w)
{
j--;
}
fo<<pp[j].v<<endl;
fi.close();
fo.close();
return 0;
}