Language: C++

#include<cstdio>
#include<iostream>

using namespace std;
#define INF 100000

int  road, max = 0, time[10][10],sum,root[10];

void dijkstra(int a) {

	int i,j,k=INF,used[10],minroot;
	for (i = 0; i <= max; i++) {
		used[i] = 0;
		root[i] = INF;
	}
	root[a] = 0;
	while (1) {
		minroot = INF;
		for (i = 0; i <= max; i++) {
			if (used[i] == 0&&root[i]<minroot) {
				j = i;
				minroot = root[i];
			}
			
		}
		if (k == j) {
			break;
		}
		else {
			k = j;
		}
		used[j] = 1;
		for (i = 0; i <= max; i++) {
			if (root[i] > root[j] + time[j][i]) {
				root[i] = root[j] + time[j][i];
			}

		}
	}
	sum = 0;
	for (i = 0; i <= max; i++)sum += root[i];

	return ;
}






int main() {
	cin >> road;
	int i, j, a, b, c, save_a[45], save_b[45],save_c[45], min_sum=INF ,ans_town;

	for (i = 1; i <= road; i++) {
		cin >> a >> b >> c;
		if (max < a) max = a;
		if (max < b) max = b;
		save_a[i] = a;
		save_b[i] = b;
		save_c[i] = c;
	}
	for (i = 0; i <= max; i++) {
		for (j = 0; j <= max; j++) {
			time[i][j] = INF;
		}
		time[i][i] = 0;
	}
	for (i = 1; i <= road; i++) {
		time[save_a[i]][save_b[i]] = save_c[i];
		time[save_b[i]][save_a[i]] = save_c[i];
	}
	for (i = 0; i <= max; i++) {
		dijkstra(i);
		if (sum < min_sum) {
			ans_town = i;
			min_sum = sum;
		}
	}
	cout << ans_town << " " << min_sum << endl;
}

Compiler output:
a.cc:7:32: error: 'int time [10][10]' redeclared as different kind of entity
    7 | int  road, max = 0, time[10][10],sum,root[10];
      |                                ^
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
a.cc: In function 'void dijkstra(int)':
a.cc:12:26: error: reference to 'max' is ambiguous
   12 |         for (i = 0; i <= max; i++) {
      |                          ^~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41:
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:7:12: note:                 'int max'
    7 | int  road, max = 0, time[10][10],sum,root[10];
      |            ^~~
a.cc:19:34: error: reference to 'max' is ambiguous
   19 |                 for (i = 0; i <= max; i++) {
      |                                  ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:7:12: note:                 'int max'
    7 | int  road, max = 0, time[10][10],sum,root[10];
      |            ^~~
a.cc:33:34: error: reference to 'max' is ambiguous
   33 |                 for (i = 0; i <= max; i++) {
      |                                  ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:7:12: note:                 'int max'
    7 | int  road, max = 0, time[10][10],sum,root[10];
      |            ^~~
a.cc:34:55: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   34 |                         if (root[i] > root[j] + time[j][i]) {
      |                                                       ^
a.cc:34:58: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   34 |                         if (root[i] > root[j] + time[j][i]) {
      |                                                          ^
a.cc:34:47: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   34 |                         if (root[i] > root[j] + time[j][i]) {
      |                                       ~~~~~~~~^~~~~~~~~~~~
a.cc:34:37: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   34 |                         if (root[i] > root[j] + time[j][i]) {
      |                             ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
a.cc:35:59: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   35 |                                 root[i] = root[j] + time[j][i];
      |                                                           ^
a.cc:35:62: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   35 |                                 root[i] = root[j] + time[j][i];
      |                                                              ^
a.cc:35:51: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   35 |                                 root[i] = root[j] + time[j][i];
      |                                           ~~~~~~~~^~~~~~~~~~~~
a.cc:35:51: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
   35 |                                 root[i] = root[j] + time[j][i];
      |                                           ~~~~~~~~^~~~~~~~~~~~
      |                                                   |
      |                                                   time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
a.cc:41:26: error: reference to 'max' is ambiguous
   41 |         for (i = 0; i <= max; i++)sum += root[i];
      |                          ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:7:12: note:                 'int max'
    7 | int  road, max = 0, time[10][10],sum,root[10];
      |            ^~~
a.cc: In function 'int main()':
a.cc:57:21: error: reference to 'max' is ambiguous
   57 |                 if (max < a) max = a;
      |                     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:7:12: note:                 'int max'
    7 | int  road, max = 0, time[10][10],sum,root[10];
      |            ^~~
a.cc:57:30: error: reference to 'max' is ambiguous
   57 |                 if (max < a) max = a;
      |                              ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:7:12: note:                 'int max'
    7 | int  road, max = 0, time[10][10],sum,root[10];
      |            ^~~
a.cc:58:21: error: reference to 'max' is ambiguous
   58 |                 if (max < b) max = b;
      |                     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:7:12: note:                 'int max'
    7 | int  road, max = 0, time[10][10],sum,root[10];
      |            ^~~
a.cc:58:30: error: reference to 'max' is ambiguous
   58 |                 if (max < b) max = b;
      |                              ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:7:12: note:                 'int max'
    7 | int  road, max = 0, time[10][10],sum,root[10];
      |            ^~~
a.cc:63:26: error: reference to 'max' is ambiguous
   63 |         for (i = 0; i <= max; i++) {
      |                          ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:7:12: note:                 'int max'
    7 | int  road, max = 0, time[10][10],sum,root[10];
      |            ^~~
a.cc:64:34: error: reference to 'max' is ambiguous
   64 |                 for (j = 0; j <= max; j++) {
      |                                  ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:7:12: note:                 '