Language: C++

/*
 * sy.cpp
 *
 *  Created on: 2012-10-7
 *      Author: Administrator
 */
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
using namespace std;

typedef long long ll;
#define zero(a) memset(a,0,sizeof(a))
const double pi = acos(-1.0);
const int inf = 0x7FFFFFFF;
const double eps = 1e-8;

int n, m;
const int N = 1005;
const int M = 10005;
int k[101][101];

bool f[101];
int tot;

struct edge {
	int next, v;
} e[M];
int head[N], index;
void init() {
	zero(head);
	index = 1;
}
inline void add(int u, int v) {
	e[index].v = v;
	e[index].next = head[u];
	head[u] = index++;
}
void bfs(int x) {
	f[x] = 1;
	tot++;
	int i, j;
	queue<int> q;
	q.push(x);
	while (!q.empty()) {
		int tmp = q.front();
		q.pop();
		for (i = head[tmp]; i; i = e[i].next) {
			if (!f[e[i].v]) {
				f[e[i].v] = 1;
				tot++;
				q.push(e[i].v);
			}
		}
	}
}
bool g[101],ac[101];
void jud(int x) {
	zero(f);
	zero(ac);
	f[x] = 1;
	queue<int> q;
	q.push(x);
	int i,j;
	while (!q.empty()) {
		int tmp = q.front();
		q.pop();
		for (i = head[tmp]; i; i = e[i].next) {
			if(tmp == x){
				ac[e[i].v] = 1;
			}
			if(e[i].v == x && ac[tmp] == 0){
				g[x] = 1;return;
			}
			if (!f[e[i].v]) {
				f[e[i].v] = 1;
				q.push(e[i].v);
			}
		}
	}

}
int m1[10000],m2[10000],t1,t2;
int main() {
	int i, j, a, b, c, ans;
	while (cin >> n >> m && (n || m)) {
		for(i = 1;i <= n;i ++){
			for(j = 1;j <= n; j++){
				k[i][j] = -inf;
			}
		}
		zero(f);
		init();
		ans = 0;
		for (i = 0; i < m; i++) {
			cin >> a >> b >> c;
			a++;
			b++;
			if (c <= 0) {
				ans += c;
				continue;
			}
			k[a][b] = max(0, k[a][b]);
			k[b][a] = max(0, k[b][a]);
			k[a][b] += c;
			k[b][a] += c;
			add(a, b);
			add(b, a);
		}

		tot = 0;
		bfs(1);
		if (tot != n) {
			cout << ans << endl;
			continue;
		}zero(g);
		for (i = 1; i <= n; i++) {
			jud(i);
		}
		t1 = t2 = 0;
		for(i = 1;i <= n;i ++){
			for(j = i+1;j <= n; j++){
				if(k[i][j] == -inf) continue;
				if(g[i]&&g[j]){
					m1[t1++] = k[i][j];
				}
				else
					m2[t2++] = k[i][j];
			}
		}
		sort(m1,m1+t1);
		sort(m2,m2+t2);
		if(t1 > 1){
			cout<<ans + min(m1[0]+m1[1],m2[0])<<endl;
		}
		else
			cout<<ans + m2[0]<<endl;
	}

}

Compiler output:
a.cc:33:14: error: 'int index' redeclared as different kind of entity
   33 | int head[N], index;
      |              ^~~~~
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from a.cc:10:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'void init()':
a.cc:36:17: error: overloaded function with no contextual type information
   36 |         index = 1;
      |                 ^
a.cc: In function 'void add(int, int)':
a.cc:39:10: error: invalid types 'edge [10005][<unresolved overloaded function type>]' for array subscript
   39 |         e[index].v = v;
      |          ^
a.cc:40:10: error: invalid types 'edge [10005][<unresolved overloaded function type>]' for array subscript
   40 |         e[index].next = head[u];
      |          ^
a.cc:41:24: error: no post-increment operator for type
   41 |         head[u] = index++;
      |                        ^~