您的位置:首页 > 其它

1003. Emergency (25)

2015-07-17 19:41 267 查看

1003. Emergency (25)

时间限制400 ms 内存限制65536 kB 代码长度限制16000 B 判题程序Standard作者CHEN, Yue As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.InputEach input file contains one test case. For each test case, the first line contains 4 positive integers: N (<= 500) - the number of cities (and the cities are numbered from 0 to N-1), M - the number of roads, C1 and C2 - the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c1, c2 and L, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from C1 to C2.OutputFor each test case, print in one line two numbers: the number of different shortest paths between C1 and C2, and the maximum amount of rescue teams you can possibly gather. All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.Sample Input5 6 0 2 1 2 1 5 3 0 1 1 0 2 2 0 3 1 1 2 1 2 4 1 3 4 1
Sample Output
2 4

评测结果

时间结果得分题目语言用时(ms)内存(kB)用户
7月19日
21:35
答案正确251003C++
(g++ 4.7.2)
3384datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分
0答案正确124810/10
1答案正确13083/3
2答案正确12563/3
3答案正确23083/3
4答案正确22563/3
5答案正确33843/3
#include<iostream>
using namespace std;
#define MAX 0x7fffffff
struct Esave
{
  long int save;
  long int LastIndex;
};

struct Mlist
{
  int to;
  long int cost;
  long int FrontIndex;
};
long int Gmap(Esave *nl, Mlist *me, long int i, int c1, int c2, long int ct)
{
  me[i].cost = ct;
  me[i].to = c2;
  me[i].FrontIndex = nl[c1].LastIndex;
  nl[c1].LastIndex = i++;

  me[i].cost = ct;
  me[i].to = c1;
  me[i].FrontIndex = nl[c2].LastIndex;
  nl[c2].LastIndex = i++;

  return i;
}
void EMDFS(Esave*nl, Mlist*me, long int *min, int c1, int c2,
  bool *visit, long int*max, long int lastmin, long int *count, long int maxx)
{
  long int t, tempmax, tempmin, id;
  visit[c1] = false;
  t = nl[c1].LastIndex;
  tempmin = lastmin;
  tempmax = maxx;
  while (t>0)
  {
    id = me[t].to;
    tempmin = lastmin + me[t].cost;
    tempmax = maxx + nl[id].save;
    if (visit[id] == true && id != c2)
      EMDFS(nl, me, min, id, c2, visit, max, tempmin, count, tempmax);
    else  if (id == c2)
    {
      if ((*min)>tempmin)
      {
        (*min) = tempmin;
        (*max) = tempmax; 
        (*count)=1;
      }
      else if ((*min) == tempmin)
      {
        if ((*max)<tempmax)
        {
          (*max) = tempmax; 
        } 
          (*count)++;
      }
    }
    t = me[t].FrontIndex;
  }
  visit[c1] = true;
}
int main()
{
  int N, i, link1, link2, C1, C2;
  long int M, costt, temp, t;
  bool *flag;
  Esave *NLastIndex;
  Mlist *MEmergency;
  cin >> N >> M >> C1 >> C2;
  NLastIndex = new Esave
;
  MEmergency = new Mlist[(M + 1) * 2];
  MEmergency[0].cost = 0;
  MEmergency[0].to = 0;
  MEmergency[0].FrontIndex = 0;
  flag = new bool
;
  for (i = 0; i<N; i++)
  {
    cin >> NLastIndex[i].save;
    NLastIndex[i].LastIndex = 0;
    flag[i] = true;

  }
  for (i = 0, temp = 1; i<M; i++)
  {
    cin >> link1 >> link2 >> costt;
    temp = Gmap(NLastIndex, MEmergency, temp, link1, link2, costt);
  }
  costt = MAX;
  temp = NLastIndex[C1].save;
  t = 1;  
  EMDFS(NLastIndex, MEmergency, &costt, C1, C2, flag, &temp, MEmergency[C1].cost, &t, temp); 
  cout << t << " " << temp << endl; 
  delete []NLastIndex;
  delete []MEmergency;
  return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: