problemscpp
A collection of my answers to algorithm problems in c++.
函数
acwing::acwing853 命名空间参考

  1. 有边数限制的最短路
更多...

函数

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

详细描述

  1. 有边数限制的最短路

函数说明

◆ main()

int acwing::acwing853::main ( istream &  cin,
ostream &  cout 
)

在文件 acwing.cpp7201 行定义.

7201 {
7202 int n;
7203 int m;
7204 int k;
7205 cin >> n >> m >> k;
7206 vector<tuple<int, int, int>> vec(m);
7207 vector shortest(n + 1, 0x3f3f3f);
7208 shortest[1] = 0;
7209 for(int i = 0; i < m; i++) {
7210 int x;
7211 int y;
7212 int z;
7213 cin >> x >> y >> z;
7214 vec[i] = make_tuple(x, y, z);
7215 }
7216 for(int i = 0; i < k; i++) {
7217 vector<int> shortest_cpy = shortest;
7218 for(auto [x, y, z]: vec) {
7219 shortest[y] = min(shortest[y], shortest_cpy[x] + z);
7220 }
7221 }
7222 if(shortest[n] > 0x3f3f3f / 2) {
7223 cout << "impossible";
7224 } else {
7225 cout << shortest[n];
7226 }
7227 return 0;
7228 }
int vec[100010]
Definition: pat.cpp:5095

引用了 pat::a::a7_2::vec.

被这些函数引用 TEST().

◆ TEST() [1/2]

acwing::acwing853::TEST ( acwing853  ,
case1   
)

在文件 acwing_test.cpp3358 行定义.

3358 {
3359 istringstream in("3 3 1\n"
3360 "1 2 1\n"
3361 "2 3 1\n"
3362 "1 3 3");
3363 auto out = ostringstream();
3364 main(in, out);
3365 const auto ans = out.str();
3366 ASSERT_EQ("3", ans);
3367 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().

◆ TEST() [2/2]

acwing::acwing853::TEST ( acwing853  ,
case2   
)

在文件 acwing_test.cpp3369 行定义.

3369 {
3370 istringstream in("10 20 8\n"
3371 "4 2 7\n"
3372 "8 7 10\n"
3373 "1 3 1\n"
3374 "7 6 1\n"
3375 "4 5 8\n"
3376 "8 7 5\n"
3377 "5 7 1\n"
3378 "6 10 2\n"
3379 "3 1 9\n"
3380 "5 4 4\n"
3381 "4 7 1\n"
3382 "9 9 9\n"
3383 "8 1 8\n"
3384 "5 4 5\n"
3385 "7 6 5\n"
3386 "3 7 7\n"
3387 "4 9 1\n"
3388 "2 1 9\n"
3389 "2 9 9\n"
3390 "6 1 -2");
3391 auto out = ostringstream();
3392 main(in, out);
3393 const auto ans = out.str();
3394 ASSERT_EQ("11", ans);
3395 }

引用了 main().