problemscpp
A collection of my answers to algorithm problems in c++.
| 函数
pat::a::a1003 命名空间参考

1003 Emergency 更多...

struct  comp
 

函数

int main (istream &cin, ostream &cout)
 
 TEST (a1003, case1)
 

详细描述

1003 Emergency

函数说明

◆ main()

int pat::a::a1003::main ( istream &  cin,
ostream &  cout 
)

< shortest_cnt[i] = number of shortest path from C1 to i

< shortest[i] = shortest distance from C1 to i

< max_rescue[i] = max rescue sum from C1 to i in shortest path

在文件 pat.cpp3954 行定义.

3954 {
3955 int N;
3956 int M;
3957 int C1;
3958 int C2;
3959 cin >> N >> M >> C1 >> C2;
3960 int max_d = 0;
3961 vector<int> rescue(N);
3962 vector grid(N, vector(N, 0));
3963 for(int i = 0; i < N; i++) {
3964 cin >> rescue[i];
3965 }
3966 for(int i = 0; i < M; i++) {
3967 int c1;
3968 int c2;
3969 int L;
3970 cin >> c1 >> c2 >> L;
3971 grid[c1][c2] = L;
3972 grid[c2][c1] = L;
3973 max_d += L;
3974 }
3975 vector shortest_cnt(N, 0);
3976 vector shortest(N, max_d + 1);
3977 vector max_rescue(N, 0);
3978 priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, comp> pq;
3979 pq.push(make_tuple(C1, 0, rescue[C1]));
3980 while(!pq.empty()) {
3981 auto [c, d, s] = pq.top();
3982 pq.pop();
3983 if(d < shortest[c]) {
3984 shortest[c] = d;
3985 shortest_cnt[c] = 1;
3986 max_rescue[c] = s;
3987 } else if(d == shortest[c]) {
3988 shortest_cnt[c]++;
3989 } else {
3990 continue;
3991 }
3992 if(s > max_rescue[c]) {
3993 max_rescue[c] = s;
3994 }
3995 for(int i = 0; i < N; i++) {
3996 if(grid[c][i] > 0 && d + grid[c][i] <= shortest[i]) {
3997 pq.push(make_tuple(i, d + grid[c][i], s + rescue[i]));
3998 }
3999 }
4000 }
4001 cout << shortest_cnt[C2] << ' ' << max_rescue[C2];
4002 return 0;
4003 }
const int N
Definition: acwing.h:146
const unsigned M
Definition: pat.h:807

引用了 pat::a::a1016::M , 以及 acwing::acwing2019::N.

被这些函数引用 TEST().

◆ TEST()

pat::a::a1003::TEST ( a1003  ,
case1   
)

在文件 pat_test.cpp1968 行定义.

1968 {
1969 istringstream in("5 6 0 2\n"
1970 "1 2 1 5 3\n"
1971 "0 1 1\n"
1972 "0 2 2\n"
1973 "0 3 1\n"
1974 "1 2 1\n"
1975 "2 4 1\n"
1976 "3 4 1");
1977 auto out = ostringstream();
1978 main(in, out);
1979 ASSERT_EQ("2 4", out.str());
1980 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().