criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	ll rw = 100*a, rs = 0;
	for(int i = 0;a*100*i <= f;i++){
		for(int j = 0;water+b*100*j <= f;j++){
			for(int k = 0;a*100*i+b*100*j+k*c <= f;k++){
				ll water = a*100*i+b*100*j;
				ll sugar = c*k;
				sugar += (min(f, water/100*e)-sugar)/d*d;
				if(sugar > water/100*e || water+sugar > f)
					continue;
				if(sugar*(rw+rs) > rs*(water+sugar)){
					rw = water;
					rs = sugar;
				}
			}
		}
	}
	cout << rs+rw << " " << rs << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:37:31: error: 'water' was not declared in this scope
   37 |                 for(int j = 0;water+b*100*j <= f;j++){
      |                               ^~~~~
Language: C++

#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int dp[3333];
int main(){
	int A,B,C,D,E,F;
	int X=-1,Y=1;
	scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	for(int i=0; i<=F; i++)if(dp[i] == 0){
		dp[i + C] = 0;
		dp[i + D] = 0;
	}
	for(int i=1; i<=F; i++){
		if(dp[i] == 0)dp[i] = i;else
			dp[i] = dp[i-1];
	}
	for(int a=0; a*A*100 <= F; a++)
	for(int b=0,tot; (tot=a*A*100 + b*B*100) <= F; b++){
		int e = min((a * A + b * B) * E, F - tot);
		int res = dp[e];
		if(res * Y > (res + tot) * X){
			X = res;
			Y = res + tot;
		}
	}
	printf("%d %d\n",Y,X);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:9: error: 'memset' was not declared in this scope
   10 |         memset(dp,-1,sizeof(dp));
      |         ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include<algorithm>
  +++ |+#include <cstring>
    4 | using namespace std;
Language: C++

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1e18;

struct UnionFind {
    vector<int> data; int sz;
    UnionFind(int sz) : data(sz, -1), sz(sz) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) { return false; }
        if (data[x] > data[y]) { swap(x, y); }
        data[x] += data[y]; data[y] = x; sz--; return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return sz; }
};

int main() {
    int N;
    bool is_ok = true;
    cin >> N;
    long long A[N][N];
    vector<vector<long long>> G(N, vector<long long>(N, INF));
    vector<pair<long long, pair<int, int>>> edges;
    for (int i = 0; i < N; i++) G[i][i] = 0;
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
        cin >> A[i][j];
        if (i < j) edges.emplace_back(A[i][j], make_pair(i, j));
    }
    // WF で最短路か判定(以降Aが最短路とする)
    // kruskal法の要領で辺の採用不採用を判定
    // 繋がっていないなら採用
    // 繋がっているとき、その辺を使って最短路が生まれるなら採用
    sort(edges.begin(), edges.end());
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
            if (chmin(A[i][j], A[i][k] + A[k][j])) is_ok = false;
        }
    }
    
    if (!is_ok) { cout << -1 << endl; return 0; }

    auto wf = [&]()->void {
        for (int k = 0; k < N; k++) {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    chmin(G[i][j], G[i][k] + G[k][j]);
                }
            }
        }
    };

    UnionFind uf(N);
    for (auto e : edges) {
        int u, v; tie(u, v) = e.second;
        long long cost = e.first;
        if (uf.unionSet(u, v)) { G[u][v] = cost; G[v][u] = cost; ans += cost; }
        else if (chmin(G[u][v], cost) && chmin(G[v][u], cost)) { wf(); ans += cost; }
    }
    
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:61:66: error: 'ans' was not declared in this scope; did you mean 'abs'?
   61 |         if (uf.unionSet(u, v)) { G[u][v] = cost; G[v][u] = cost; ans += cost; }
      |                                                                  ^~~
      |                                                                  abs
a.cc:62:72: error: 'ans' was not declared in this scope; did you mean 'abs'?
   62 |         else if (chmin(G[u][v], cost) && chmin(G[v][u], cost)) { wf(); ans += cost; }
      |                                                                        ^~~
      |                                                                        abs
a.cc:65:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   65 |     cout << ans << endl;
      |             ^~~
      |             abs
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)

signed main(){
	int n;cin>>n;
	vector<vector<int>> a(n,vector<int>(n));
	vector<vector<int>> b(n,vector<int>(n));
	vector<vector<bool>> c(n,vector<bool>(n,true));


rep(i,n)rep(j,n){cin>>a[i][j];b[i][j]=a[i][j];}

rep(i,n)rep(j,n)rep(k,n)a[i][j]=min(a[i][j],a[i][k]+a[k][j]);

rep(i,n)rep(j,n){if(a[i][j]!=b[i][j])cuot<<-1<<endl,exit(0);}

rep(i,n)rep(j,n)rep(k,n)if(a[i][j]=a[i][k]+a[k][j])c[i][j]=false;

int ret=0;
rep(i,n)rep(j,n){if(c[i][j])ret+=a[i][j];}
cout<<ret<<endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:38: error: 'cuot' was not declared in this scope
   17 | rep(i,n)rep(j,n){if(a[i][j]!=b[i][j])cuot<<-1<<endl,exit(0);}
      |                                      ^~~~
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
	cout<<-1<<endl
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:23: error: expected ';' before 'return'
   19 |         cout<<-1<<endl
      |                       ^
      |                       ;
   20 |     return 0;
      |     ~~~~~~
Language: C++

#include "stdafx.h"
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };



ll n;
ll dist_1[305][305];
ll dist_2[305][305];
ll mincost[305];
bool used[305];


int main() {
	cin >> n;
	ll sum = 0;
	rep(i, 0, n)rep(j, 0, n) {
		ll x;
		cin >> x;
		dist_1[i][j] = x;
		dist_2[i][j] = x;
		if (i > j)sum += x;
	}

	rep(k, 0, n)rep(i, 0, n)rep(j, 0, n) {
		dist_1[i][j] = min(dist_1[i][j], dist_1[i][k] + dist_1[k][j]);
	}

	bool ok = 1;
	rep(i, 0, n)rep(j, 0, n) {
		if (dist_1[i][j] != dist_2[i][j])ok = 0;
	}

	if (!ok) {
		cout << "-1" << endl;
		exit(0);
	}

	rep(i, 0, n)rep(j, 0, n) {
		bool fl = 0;
		rep(k, 0, n) {
			if (i < j && k != i && k != j) {
				if (dist_1[i][j] >= dist_1[i][k] + dist_1[k][j] && fl == 0) {
					sum -= dist_1[i][j];
					fl = 1;
				}
			}
		}
	}

	cout << sum << endl;


	return 0;
}

Compiler output:
a.cc:1:10: fatal error: stdafx.h: No such file or directory
    1 | #include "stdafx.h"
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
#define int long long
int g[300][300];
int w[300][300];
using namespace std;

signed main(){
  const int INF=1e18;
  int N;
  cin>>N;
  int out=0;
  for(int i=0;i<N;i++)for(int j=0;j<N;j++)if(i!=j)w[i][j]=INF;
  for(int i=0;i<N;i++)for(int j=0;j<N;j++)cin>>g[i][j];
  int ans=0;
  typedef pair<int,int> P;
  priority_queue<P,vector<P>,greater<P>> que;
  for(int i=0;i<N;i++){
    for(int j=0;j<i;j++){
      que.push(P(g[i][j],i*1000+j));
    }
  }
  while(que.size()){
    P p=que.top();que.pop();
    int mi=(p.second)/1000;
    int mj=(p.second)%1000;
    if(p.first==w[mi][mj])continue;
    if(p.first>w[mi][mj]){
      out++;
      continue;
    }
    w[mi][mj]=p.first;
    ans+=p.first;
    for(k=0;k<N;k++){
    for(int i=mi+1;i<N;i++){
      if(i>mj)w[i][mi]=min(w[i][mi],w[i][mj]+w[mi][mj]);
      if(i<mj)w[i][mi]=min(w[i][mi],w[mj][i]+w[mi][mj]);
    }
    for(int i=mj+1;i<N;i++){
      if(i>mi)w[i][mj]=min(w[i][mj],w[i][mi]+w[mi][mj]);
      if(i<mi)w[i][mj]=min(w[i][mj],w[mi][i]+w[mi][mj]);
    }
    for(int i=0;i<mi;i++){
      if(i<mj)w[mi][i]=min(w[mi][i],w[mi][mj]+w[mj][i]);
      if(i>mj)w[mi][i]=min(w[mi][i],w[mi][mj]+w[i][mj]);
    }
    for(int i=0;i<mj;i++){
      if(mi>i)w[mj][i]=min(w[mj][i],w[mi][mj]+w[mi][i]);
      if(mi<i)w[mj][i]=min(w[mj][i],w[mi][mj]+w[i][mi]);
    }
  }}
  if(out)cout<<-1<<endl;
  else cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:33:9: error: 'k' was not declared in this scope
   33 |     for(k=0;k<N;k++){
      |         ^
Language: C++

#include <bits/stdc++.h>

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,grid[301][301];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
  
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin >> n;
      rep(i,n)rep(j,n)cin>>grid[i][j];
      ll flo[301][301];
      rep(i,n){
          rep(j,n){
              if(i==j)flo[i][j]=0;
              else flo[i][j]=LINF;
          }
      }
      rep(i,n){
          rep(j,n){
              if(i>j)continue;
              flo[i][j]=grid[i][j];
              flo[j][i]=grid[i][j];
          }
      }
      rep(i,n){
          rep(j,n){
              rep(k,n){
                  flo[j][k]=min(flo[j][k],flo[j][i]+flo[i][k]);
              }
          }
      }
      rep(i,n){
          rep(j,n){
              if(i<j)continue;
              if(flo[i][j]!=grid[i][j])fl=true;
          }
      }
      if(fl)Cout(-1);
      else{
          rep(i,n){
              //rep(j,n){
                  ans+=flo[i][j];
              //}
          }
          Cout(ans/2);
      }
       
return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:64:31: error: 'j' was not declared in this scope
   64 |                   ans+=flo[i][j];
      |                               ^
Language: C++

#include<bits/stdc++.h>

using namespace std;

const int maxn=500;
int n;
long long dp[maxn][maxn];
long long sum=0;
int floyd() {
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= i; j++){
                if(i==j) continue;
                int flag=1;
            for (int k = 1; k <= n; k++){
                if(i==k || j==k) continue;
               if(dp[i][j]>dp[i][k]+dp[k][j]){
                    cout<<-1;
                    return 0;
               }
               if(dp[i][j]==dp[i][k]+dp[k][j]){
                    flag=0;
               }

               if(flag)
                sum+=dp[i][j];
            }
        }
        cout<<sum;
        return 0;
}


Compiler output:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cstdio>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POSSIBLE(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Possible(i) cout<<(i?"Possible":"Impossible")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=998244353;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
ll GCD(ll A,ll B){
  return (B==0)?(A):(GCD(B,A%B));
}
ll LCM(ll A,ll B){
  return A/GCD(A,B)*B;
}
//
int main(){
	int N;
	ll A[300][300];
	vector<pair<ll,pair<int,int> > > V;
	cin>>N;
	FOR(i,0,N){
		FOR(j,0,N){
			cin>>a;
			if(i<j){
				V.PB(MA(a,MA(i,j)));
			}
			if(i!=j){
				A[i][j]=1e15;
			}
		}
	}
	sort(V.begin(),V.end());
	ll ans=0;
	FOR(k,0,V.size()){
		ll v=V[k].FI;
		int x=V[k].SE.FI;
		int y=V[k].SE.SE;
		if(A[x][y]>v){
			ans+=v;
			FOR(i,0,N){
				FOR(j,0,N){
					A[i][j]=min(A[i][j],A[i][x]+v+A[y][j]);
					A[i][j]=min(A[i][j],A[i][y]+v+A[x][j]);
				}
			}
		}
	}
	FOR(i,0,V.size()){
		ll v=V[i].FI;
		int x=V[i].SE.FI;
		int y=V[i].SE.SE;
		if(A[x][y]!=v){
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:30: error: 'a' was not declared in this scope
   51 |                         cin>>a;
      |                              ^
Language: C++

import qualified Data.Array.IO as A
import Data.Array as U
import Control.Monad
import Data.Maybe

main = do
    n <- read <$> getLine :: IO Int
    as <- warshall_fluyd =<< A.newListArray ((1,1),(n,n)) . map Just . concat =<< 
            replicateM n (map read . words <$> getLine) 

    if isJust as 
        then print . sum $ map (\(i,j)->fromMaybe 0 $ fromJust as!(i,j)) [(i,j)|i<-[1..n], j<-[1..n], i<j, i/=j]
        else putStrLn "-1"

warshall_fluyd :: A.IOArray (Int,Int) (Maybe Int) -> IO (Maybe (U.Array (Int,Int) (Maybe Int)))
warshall_fluyd arr = do
    ((s,_),(l,_)) <- A.getBounds arr
    f <- and <$> (forM [(k,i,j)|k<-[s..l], i<-[s..l], j<-[s..l], i/=j, k/=j, i/=k] $ \(k,i,j) -> do
        ik <- A.readArray arr (i,k)
        kj <- A.readArray arr (k,j)
        ij <- A.readArray arr (i,j)
        if all isJust [ik,kj,ij]
            then if fromJust ik+ fromJust kj == fromJust ij
                then do A.writeArray arr (i,j) Nothing
                        return True
                else if fromJust ik+ fromJust kj < fromJust ij
                    then return False
                    else return True
            else return True)
    if f then Just <$> A.freeze arr else return Nothing


Compiler output:
a.cc:12:33: error: stray '\' in program
   12 |         then print . sum $ map (\(i,j)->fromMaybe 0 $ fromJust as!(i,j)) [(i,j)|i<-[1..n], j<-[1..n], i<j, i/=j]
      |                                 ^
a.cc:12:85: error: too many decimal points in number
   12 |         then print . sum $ map (\(i,j)->fromMaybe 0 $ fromJust as!(i,j)) [(i,j)|i<-[1..n], j<-[1..n], i<j, i/=j]
      |                                                                                     ^~~~
a.cc:12:96: error: too many decimal points in number
   12 |         then print . sum $ map (\(i,j)->fromMaybe 0 $ fromJust as!(i,j)) [(i,j)|i<-[1..n], j<-[1..n], i<j, i/=j]
      |                                                                                                ^~~~
a.cc:18:86: error: stray '\' in program
   18 |     f <- and <$> (forM [(k,i,j)|k<-[s..l], i<-[s..l], j<-[s..l], i/=j, k/=j, i/=k] $ \(k,i,j) -> do
      |                                                                                      ^
a.cc:1:1: error: 'import' does not name a type
    1 | import qualified Data.Array.IO as A
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
Language: C++

#include<bits/stdc++.h>
using namespace std;

map<string,string>mp;
map<string,string>::iterator it;
void prepare()
{

    mp[".-"]="A";
    mp["-..."]="B";
    mp["-.-."]="C";
    mp["-.."]="D";
    mp["."]="E";
    mp["..-."]="F";
    mp["--."]="G";
    mp["...."]="H";
    mp[".."]="I";
    mp[".---"]="J";
    mp["-.-"]="K";
    mp[".-.."]="L";
    mp["--"]="M";
    mp["-."]="N";
    mp["---"]="O";
    mp[".--."]="P";
    mp["--.-"]="Q";
    mp[".-."]="R";
    mp["..."]="S";
    mp["-"]="T";
    mp["..-"]="U";
    mp["...-"]="V";
    mp[".--"]="W";
    mp["-..-"]="X";
    mp["-.--"]="Y";
    mp["--.."]="Z";

    mp["-----"]="0";
    mp[".----"]="1";
    mp["..---"]="2";
    mp["...--"]="3";
    mp["....-"]="4";
    mp["....."]="5";
    mp["-...."]="6";
    mp["--..."]="7";
    mp["---.."]="8";
    mp["----."]="9";

    mp[".-.-.-"]=".";
    mp["--..--"]=",";
    mp["..--.."]="?";
    mp[".----."]="'";
    mp["-.-.--"]="!";
    mp["-..-."]="/";
    mp["-.--."]="(";
    mp["-.--.-"]=")";
    mp[".-..."]="&";

    mp["---..."]=":";
    mp["-.-.-."]=";";
    mp["-...-"]="=";
    mp[".-.-."]="+";
    mp["-....-"]="-";
    mp["..--.-"]="_";
    mp[".-..-."]="\"";
    mp[".--.-."]="@";



}


int main()
{

   // freopen("input.txt", "r", stdin);
    prepare();
//
//    vector<string>vec;
//
//    for(it=mp.begin(); it!=mp.end(); it++)
//        vec.push_back(it->second);
//
//    sort(vec.begin(),vec.end());
//
//    for(int i=0; i<vec.size(); i++)
//        cout<<vec[i]<<endl;
//
//    return 0;



    int tt,test;
    scanf("%d",&test);
    getchar();

    for(int tt=0; tt<test; tt++)
    {

        if(tt>0)
            puts("");



        char a[20009];
        gets(a);

        string str(a);
        str+=" ";

        string temp, t,text;
        int flag=0;
        for(int i=0; i<str.size(); i++)
        {
            if(str[i]==' ')
            {

                if(str[i-1]==' ')
                {
                    text+=" ";
                    continue;
                }

                //cout<<temp<<endl;


                text+=mp[temp];
                temp="";

            }
            else
            {
                t=str[i];
                temp+=t;
            }
        }

        printf("Message #%d\n",tt+1);
        cout<<text<<endl;

    }



    return 0;

}



Compiler output:
a.cc: In function 'int main()':
a.cc:104:9: error: 'gets' was not declared in this scope; did you mean 'getw'?
  104 |         gets(a);
      |         ^~~~
      |         getw
Language: C++

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
using namespace std;
typedef pair<int, int> P;
typedef long long LL;

#define _CRT_SECURE_NO_WARNINGS
int N;
int main() {
	
	return 0;
}

for (int j = 1; j <= N; j++) {
	for (int k = 1; k < j; k++) {
		printf("%dから%d:%d\n", j, k, minL[j][k]);
	}
}

Compiler output:
a.cc:19:1: error: expected unqualified-id before 'for'
   19 | for (int j = 1; j <= N; j++) {
      | ^~~
a.cc:19:17: error: 'j' does not name a type
   19 | for (int j = 1; j <= N; j++) {
      |                 ^
a.cc:19:25: error: 'j' does not name a type
   19 | for (int j = 1; j <= N; j++) {
      |                         ^
Language: Java

import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

public class road {

    static class Edge {
        int start;
        int end;
        int weight;
        public Edge(int start, int end, int weigth) {
            this.start = start;
            this.end = end;
            this.weight = weigth;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] graph = new int[N][N];

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                graph[i][j] = sc.nextInt();
            }
        }

        if (!legitGraph(graph)) {
            System.out.println(-1);
            return;
        } else {
            System.out.println(MST(graph));
            return;
        }


    }

    private static boolean legitGraph(int[][] graph) {
        int N = graph.length;
        for (int k = 0; k < N; k++) {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    if (graph[i][j] > graph[i][k] + graph[k][j]) {
                        return false;
                    }
                }
            }
        }

        return true;
    }


    private static long MST(int[][] graph) {
        Set<Edge> edges = new HashSet<>();
        for (int i = 0; i < graph.length; i++) {
            for (int j = i + 1; j < graph.length; j++) {
                edges.add(new Edge(i, j, graph[i][j]));
            }
        }

        long ans = 0;
        for (Edge edge : edges) {
            if (important(graph, edge)) ans += edge.weight;
        }

        return ans;
    }

    private static boolean important(int[][] graph, Edge edge) {
        int a = edge.start;
        int b = edge.end;
        int weigth = edge.weight;
        for (int i = 0; i < graph.length; i++) {
            if (weigth == graph[a][i] + graph[i][b] && a != i && i != b)
                return false;
        }
        return true;
    }
}


Compiler output:
Main.java:6: error: class road is public, should be declared in a file named road.java
public class road {
       ^
1 error
Language: Java

import java.util.*;

// 考察：
// 二つの都市を通るエッジは、同じ行・列にある一つの都市のみを通るエッジを一つずつ引っ張ってきたものの和
// 同様に、三つの都市を通るエッジは、二つの都市までを通るエッジの和
// 各行で最小の値を引いてきたものは必ず一都市のみを通るエッジ

public class Main {
    public static void main(String[] args) {
        System.out.println();
    }

    private static int solve(Scanner scanner) {
        int result = 0;

        // 探索キュー
        Queue<Integer> qi = new LinkedList<>();
        Queue<Integer> qj = new LinkedList<>();

        // 既に展開したエッジのリスト
        List<Integer> vi = new ArrayList<>();
        List<Integer> vj = new ArrayList<>();

        // 確実な１都市エッジを列挙
        int N = Integer.parseInt(scanner.nextLine());
        int[][] matrix = new int[][];
        for (int i = 0; i < N; i ++) {
            int min = Integer.MAX_VALUE;
            int minJ = -1;
            String[] split = scanner.nextLine().split(" ");
            for (int j = i + 1; j < N; j ++) {
                matrix[i][j] = Integer.parseInt(split[j]);
                if (min > matrix[i][j]) {
                    min = matrix[i][j];
                    minJ = j;
                }
            }
            qi.add(i);
            qj.add(minJ);

            vi.add(i);
            vj.add(minJ);

            result += min;
        }

        // 残りの1都市エッジを全て列挙したのち2都市以上のエッジについて以下を確認
        // 確定エッジの交差点(elm)全てが１都市エッジの和(sum)になっていることを確認
        // 和になっていない場合：
        //   sum > elm の場合はそこが1都市エッジ
        //   sum < elm の場合は return -1
        Queue<Integer> qiNext = new LinkedList<>();
        Queue<Integer> qjNext = new LinkedList<>();
        while(true) {
            if (qi.size() != qj.size() || qiNext.size() != qjNext.size() || vi.size() != vj.size()) {
                throw new RuntimeException();
            }

            if (qi.isEmpty() && qiNext.isEmpty()) {
                break;
            } else if (qi.isEmpty()) {
                qi = qiNext;
                qj = qjNext;

                qiNext = new LinkedList<>();
                qjNext = new LinkedList<>();
            }

            int i = qi.poll();
            int j = qj.poll();

            for (int k = 0; k < vi.size(); k ++) {
                int ii = vi.get(k);
                int jj = vi.get(k);

                if (i == ii || j == jj) {
                    continue;
                } else {
                    int sum = matrix[i][j] + matrix[ii][jj];
                    int iii, jjj;
                    if (i < ii && j > jj) {
                        iii =
                    }
                    if (sum > )
                }
            }
        }
    }
}



Compiler output:
Main.java:26: error: array dimension missing
        int[][] matrix = new int[][];
                                    ^
Main.java:83: error: illegal start of expression
                    }
                    ^
Main.java:84: error: illegal start of expression
                    if (sum > )
                              ^
Main.java:85: error: illegal start of statement
                }
                ^
4 errors
Language: C++

import java.util.*;

public class Main
{

    static Scanner sc = new Scanner(System.in);
    static int dp[][][];
    static int edges[][];
    static boolean del[][];
    public static void main(String[] args) {
        int n = sc.nextInt();

        edges = new int[n][n];
        del = new boolean[n][n];
        long total = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                edges[i][j] = sc.nextInt();
                total += edges[i][j];
            }
        }
        dp = new int[n][n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                dp[i][j][0] = edges[i][j];
            }
        }
        for (int k = 1; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    dp[i][j][k] = Math.min(dp[i][j][k-1], dp[i][k][k-1] + dp[k][j][k-1]);
                }
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i != j && dp[i][j][n-1] != edges[i][j]){
                    System.out.println(-1);
                    return;
                }
            }
        }
        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (i!=j&& j!=k && i !=k &&edges[i][j] == edges[i][k] + edges[k][j] && !del[i][j]) {
                        total -= edges[i][j];
                        del[i][j] = true;
                    }
                }
            }
        }

        total /= 2;
        System.out.println(total);
    }
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: expected unqualified-id before 'public'
    3 | public class Main
      | ^~~~~~
Language: C++

#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <limits>

using namespace std;

int64_t distance(vector<vector<int64_t>> const &mat, int64_t a, int64_t b)
{
    priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t>>, std::greater<pair<int64_t, int64_t>>> q;
    vector<int64_t> mindist;
    mindist.resize(mat.size(), numeric_limits<int64_t>::max());

    q.push({0, a});
    while (!q.empty())
    {
        auto t = q.top();
        q.pop();
        if (t.second == b)
            continue;
        for (int64_t i = 0; i < mat.size(); i++)
        {
            if (mat[t.second][i] != -1 && mat[t.second][i] + t.first < mindist[i])
            {
                mindist[i] = mat[t.second][i] + t.first;
                q.push({mindist[i], i});
            }
        }
    }

    return mindist[b];
}

int main()
{
    int64_t n;
    cin >> n;
    vector<vector<int64_t>> mat(n);
    for (auto &x : mat)
        x.resize(n, -1);

    using dist_t = pair<int64_t, pair<int64_t, int64_t>>;
    priority_queue<dist_t, vector<dist_t>, std::greater<dist_t>> dist;
    for (int64_t i = 0; i < n; i++)
    {
        for (int64_t j = 0; j < n; j++)
        {
            int64_t temp;
            cin >> temp;
            if (j < i)
                dist.push({temp, {i, j}});
        }
    }

    int64_t ans = 0;
    while (!dist.empty())
    {
        auto t = dist.top();
        dist.pop();
        auto dis_ab = distance(mat, t.second.first, t.second.second);
        if (dis_ab == INT_MAX || dis_ab > t.first)
        {
            mat[t.second.first][t.second.second] = mat[t.second.second][t.second.first] = t.first;
            ans += t.first;
        }
        else
        {
            if (dis_ab < t.first)
            {
                ans = -1;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:62:23: error: 'INT_MAX' was not declared in this scope
   62 |         if (dis_ab == INT_MAX || dis_ab > t.first)
      |                       ^~~~~~~
a.cc:6:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    5 | #include <limits>
  +++ |+#include <climits>
    6 |
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<vector<int> > map;
int N;
class road {
public:
	int a;
	int b;
	int far;
	road(int c, int d, int e) :a(c), b(d), far(e) {}
};
bool compare(road &a, road &b) {
	return a.far < b.far;
}


bool func(road& a, int num) {
	return a.a != num&&a.b != num;
}

int find(road &ro) {
	int res = INT_MAX;
	for (int i = 1; i <= N; ++i) {
		if (func(ro, i)) {
			int a = map[i][ro.a];
			int b = map[i][ro.b];
			res = min(res, a + b);
		}
	}
	return res;
}
int main() {
	cin >> N;
	map.resize(N+1);
	for (int i = 1; i <= N; ++i) {
		map[i].resize(N + 1);
		for (int j = 1; j <= N; ++j) {
			cin >> map[i][j];
		}
	}
	vector<road> list;
	for (int i = 1; i <= N; ++i) {
		for (int j = i + 1; j <= N; ++j) {
			list.push_back(road(i, j, map[i][j]));
		}
	}
	sort(list.begin(), list.end(), compare);
	long long ans = 0;
	for (int i = 0; i < list.size(); ++i) {
		int num = find(list[i]);
		int num2 = map[list[i].a][list[i].b];
		if (num > num2) {
			ans += num2;
		}
		else if (num < num2) {
			ans = -1;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int find(road&)':
a.cc:24:19: error: 'INT_MAX' was not declared in this scope
   24 |         int res = INT_MAX;
      |                   ^~~~~~~
a.cc:4:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    3 | #include<vector>
  +++ |+#include <climits>
    4 | using namespace std;
Language: C++

#include<bits/stdc++.h>
using namespace std;
 
#include<bits/stdc++.h>
using namespace std;
using ll=long long; 
using Weight=ll;
struct Edge {
    int src,dest; Weight weight;
    bool operator<(const Edge &rhs)const{
        return weight<rhs.weight;
    }
};
using Edges=vector<Edge>;
using Graph=vector<Edges>;
 
const Weight INF=1e12;
 
void dijkstra(const Graph &g,int s,vector<Weight> &d){
    assert(0<=s && s<g.size());
    d.assign(g.size(),INF); d[s]=0;
    vector<int> used(g.size(),0);
    using P=pair<Weight,int>;
    priority_queue<P,vector<P>,greater<P>> que;
    que.push({0,s});
    while(!que.empty()){  
        auto val=que.top(); que.pop();
        Weight dist=val.first;
        int v=val.second;
        if(used[v]) continue;
        used[v]=true;
        for(auto e:g[v]){
            int to=e.dest;
            Weight w=e.weight;
            if(dist+w<d[to]){
                d[to]=dist+w;
                que.push({d[to],to});
            }
        }
    }
}
 
 
 
 
int main(){
    cin.tie(0);
    ios::sync_with_stream(false);
    int n;
    cin>>n;
    vector<vector<ll>> edge(n,vector<ll>(n,0));
    for(int i=0;i<n;i++)for(int j=0;j<n;j++) cin>>edge[i][j];
    
    const ll INF=1e15;
    vector<vector<ll>> d(n,vector<ll>(n,INF));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j]=edge[i][j];
        }
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    if(d!=edge){
        cout<<-1<<endl;
        return 0;
    }
 
    using pp=pair<ll,pair<int,int>>;
    priority_queue<pp,vector<pp>,greater<>> que;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            que.push({edge[i][j],{i,j}});
        }
    }
 
    ll res=0;
    Graph g(n);
    while(!que.empty()){
        auto val=que.top();
        que.pop();
        long long int cost=val.first;
        int a=val.second.first;
        int b=val.second.second;
        vector<ll> d(n,INF);
        dijkstra(g,a,d);
        if(d[b]!=cost){
            res+=cost;
            Edge e;
            e.src=a;
            e.dest=b;
            e.weight=cost;
            g[a].push_back(e);
            e.src=b;
            e.dest=a;
            g[b].push_back(e);
        }
    }
    cout<<res<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:10: error: 'sync_with_stream' is not a member of 'std::ios' {aka 'std::basic_ios<char>'}
   48 |     ios::sync_with_stream(false);
      |          ^~~~~~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


/*************************************************************************/
ll ans=0;
int main()
{
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;

    VVI tab(n, VI(n));
    FOR(i,0,n-1) FOR(j,0,n-1)
    {
        cin >> tab[i][j];
        ans+=tab[i][j];
    }

    FOR(k,0,n-1) FOR(i,0,n-1) FOR(j,0,n-1)
    {
        if (tab[i][j] > tab[i][k] + tab[k][j])
        {
            cout << -1;
            return 0;
        }
    }

    ll total = 0;
    FOR(k,0,n-1) FOR(i,0,n-1)
    {
        bool found = false;

        FOR(j,0,n-1) if (j != i && j != k && tab[i][j] == tab[i][k] + tab[k][j])
        {
            found = true;
        }

        if (found)
        {
            total += tab[i][j];
        }
    }

    cout << ans/2-total / 2;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:74:29: error: 'j' was not declared in this scope
   74 |             total += tab[i][j];
      |                             ^
Language: C++

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;

#define f first
#define s second
//#define p pair<int,int>
#define P pair<ll,ll>
#define pb push_back
#define ll long long
#define db double
#define zero(a) memset(a,0,sizeof(a))
#define inff(a,n) fill(a,a+n+1,inf)
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define read(x) scanf("%lld",&x)
#define read2(x,y) scanf("%lld%lld",&x,&y)
#define write(x) printf("%lld\n",x)
#define lson p*2,l,mid
#define rson p*2+1,mid+1,r

const int maxn=2e5+10;
const ll inf=1e9;
const ll mod=998244353;

ll n,m,k,T,x,a[400][400],dp[400][400],ans,sum,flag;

int main()
{
    read(n);
    //for(int i=0;i<=301;i++)for(int j=0;j<=301;j++)dp[i][j]=inf;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            read(a[i][j]);
            dp[i][j]=a[i][j];
            sum+=a[i][j];
        }
    }
    for(int k=1;k<=n;k++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int i=1;i<=n;i++)
            {
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(a[i][j]>dp[i][j]){flag=1;goto out;}
        }
    }
    for(int k=1;k<=n;k++)
    {
        for(int i,j=1;j<=n;j++)
        {
            int ok=0;
            for(i=1;i<=n;i++)
            {
                if(i!=j&&i!=k&&j!=k&&a[i][j]=a[i][k]+a[k][j])ok=1;
            }
            if(ok)ans+=a[i][j];
        }
    }
    out:
        if(flag)printf("-1");
        else printf("%lld",sum/2-ans/2);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:69:36: error: lvalue required as left operand of assignment
   69 |                 if(i!=j&&i!=k&&j!=k&&a[i][j]=a[i][k]+a[k][j])ok=1;
      |                    ~~~~~~~~~~~~~~~~^~~~~~~~~
Language: C++

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;

#define f first
#define s second
//#define p pair<int,int>
#define P pair<ll,ll>
#define pb push_back
#define ll long long
#define db double
#define zero(a) memset(a,0,sizeof(a))
#define inff(a,n) fill(a,a+n+1,inf)
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define read(x) scanf("%lld",&x)
#define read2(x,y) scanf("%lld%lld",&x,&y)
#define write(x) printf("%lld\n",x)
#define lson p*2,l,mid
#define rson p*2+1,mid+1,r

const int maxn=2e5+10;
const ll inf=1e9;
const ll mod=998244353;

ll n,m,k,T,x,a[400][400],dp[400][400],ans,sum,flag;

int main()
{
    read(n);
    //for(int i=0;i<=301;i++)for(int j=0;j<=301;j++)dp[i][j]=inf;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            read(a[i][j]);
            dp[i][j]=a[i][j];
            if(i==j&&a[i][j])
            {
                flag=1;
                goto out;
            }
            sum+=a[i][j];
        }
    }
    for(int k=1;k<=n;k++)
    {
        for(int j=1;j<=n;j++)
        {
            int ok=0;
            for(int i=1;i<=n;i++)
            {
                if(i!=k&&i!=j&&j!=k&&a[i][j]==a[i][k]+a[k][j])ok=1;
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
            if(ok)ans+=a[i][j];
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(a[i][j]>dp[i][j]){flag=1;goto out;}
        }
    }
    //cout<<sum<<" "<<ans<<endl;
    out:
        if(flag)printf("-1");
        else printf("%lld",sum/2-ans/2);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:60:26: error: 'i' was not declared in this scope
   60 |             if(ok)ans+=a[i][j];
      |                          ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset((a),(b),sizeof(a))
const int INF=0x3f3f3f3f;
const int N=305;
int g[N][N];
int d[N];
bool vis[N];
int n,m;

void Dijkstra(int s)
{
    mem(d,INF);
    mem(vis,false);
    d[s]=0;
    
    while(true)
    {
        int v=-1;
        for(int i=1;i<=n;i++)
        if(!vis[i]&&(v==-1||d[i]<d[v]))v=i;
        
        if(v==-1)break;
        vis[v]=true;
        
        for(int i=1;i<=n;i++)
        {
            d[i]=min(d[i],d[v]+g[v][i]);
        }
    }
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>g[i][j];
	
	ll ans=0;
	bool flag=true;
	for(int i=0;i<n;i++)
	{
		Dijkstra(i);
		for(int j=i+1;j<n;j++)
		{
			if(d[j]>g[i][j])flag=false;
			ans+=d[j];
		}
	}
	
	if(flag)cout<<ans<<endl;
	else cout<<-1<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:9: error: 'll' was not declared in this scope
   43 |         ll ans=0;
      |         ^~
a.cc:51:25: error: 'ans' was not declared in this scope; did you mean 'abs'?
   51 |                         ans+=d[j];
      |                         ^~~
      |                         abs
a.cc:55:23: error: 'ans' was not declared in this scope; did you mean 'abs'?
   55 |         if(flag)cout<<ans<<endl;
      |                       ^~~
      |                       abs
Language: C++

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

LL f[500][500];
LL sum;
int flag = 1;
int n;

void yu()
{
	for(int k = 1 ; k <= n ; k++){
		for(int i = 1 ; i <= n ; i++){
			for(int j = 1 ; j <= n ; j++){
				if(i == j || i == k || j == k) continue;
				if(f[i][k] + f[k][j] == f[i][j]) sum += f[i][j];
				if(f[i][k] + f[k][j] < f[i][j]) flag = 0;
			}
		}
	}
}

int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	LL ans = 0;
	scanf("%d",&n);
	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= n ; j++){
			LL x;
			scanf("%lld",&x);
			f[i][j] = x;
			ans += x;
		}
	}
	yu()
	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= n ; j++){
			if(f[i][j] != f[j][i]) flag = 0;
		}
	}
	if(flag == 0) printf("-1\n");
	else{
		printf("%lld\n",(ans - sum) / 2);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:13: error: expected ';' before 'for'
   48 |         yu()
      |             ^
      |             ;
   49 |         for(int i = 1 ; i <= n ; i++){
      |         ~~~  
a.cc:49:25: error: 'i' was not declared in this scope
   49 |         for(int i = 1 ; i <= n ; i++){
      |                         ^
Language: C++


/*
   О НЕТ! ОНИ ДОГОНЯЮТ!!!
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
*/

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

const int N = 300 + 1;

int d[N][N];
int pr[N];

int get(int v)
{
    if (v == pr[v])
    {
        return v;
    }
    else
    {
        return pr[v] = get(pr[v]);
    }
}

void uni(int u, int v)
{
    pr[get(u)] = get(v);
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            int x;
            scanf("%d", &x);
            d[i][j] = x;
        }
    }
    vector <pair <int, pair <int, int> > > e;
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            int best = INT_MAX;
            for (int k = 0; k < n; k++)
            {
                if (k != i && k != j)
                {
                    best = min(best, d[i][k] + d[k][j]);
                }
            }
            if (d[i][j] == best)
            {
                e.push_back({d[i][j], {i, j}});
            }
            else if (d[i][j] < best)
            {
                uni(i, j);
                ans += d[i][j];
            }
            else
            {
                cout << -1 << '\n';
                return 0;
            }
        }
    }
    sort(e.begin(), e.end());
    for (auto c : e)
    {
        int u = c.second.first, v = c.second.second;
        if (get(u) != get(v))
        {
            ans += c.first;
        }
    }
    printf("%lld\n", ans);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:84:24: error: 'INT_MAX' was not declared in this scope
   84 |             int best = INT_MAX;
      |                        ^~~~~~~
a.cc:33:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   32 | #include <iomanip>
  +++ |+#include <climits>
   33 |
Language: C++

#include<bits/stdc++.h>
#include<queue>
using namespace std;
void cha(int &a, int b) {
  if (b == -1) return;
  if (a == -1 || a > b) {
    a = b;
  }
}
int main () {
  int N;
  cin >> N;
  vector<vector<int>>son(N + 1, vector<int>(N + 1));
  vector<int>si(N + 1, 0);
  for (int i = 2; i <= N; i ++) {
    int a;
    cin >> a;
    son[a][si[a]] = i;
    si[a] ++;
  }
  vector<int>X(N + 1);
  for (int i = 1; i <= N; i ++) cin >> X[i];
  vector<int>per;
  queue<int>que;
  que.push(1);
  per.push_back(1);
  while(!que.empty()) {
    int u = que.front();
    for (int i = 0; i < si[u]; i ++) {
      int ne = son[u][i];
      per.push_back(ne);
      que.push(ne);
    }
    que.pop();
  }
  int dp[1010];
  for (int i = N - 1; i >= 0; i --) {
    int nw = per[i];
    if (!si[nw]) dp[nw] = 0;
    else {
      vecotr<vector<int>>dp_(si[nw] + 1, vector<int>(5050, -1));
      dp_[0][0] = 0;
      for (int i_ = 1; i_ <= si[nw]; i_ ++) {
        int so = son[nw][i_];
        for (int j = X[nw]; j >= 0; j --) {
          if (j + X[so] <= X[nw] && dp_[i - 1][j] != -1) {
            cha(dp_[i][j + X[so]], dp_[i - 1][j] + dp[so]);
          }
          if (j + dp[so] <= X[nw] && dp_[j] != -1) {
            cha(dp_[i][j + dp[so]], dp_[i - 1][j] + X[so]);
          }
        }
      }
      dp[nw] = -1;
      for (int i_ = 1; i_ <= X[nw]; i_ ++) {
        cha(dp[nw], dp_[si[nw]][i]);
      }
      if (dp[nw] == -1) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "POSSIBLE" << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:41:7: error: 'vecotr' was not declared in this scope
   41 |       vecotr<vector<int>>dp_(si[nw] + 1, vector<int>(5050, -1));
      |       ^~~~~~
a.cc:41:24: error: expected primary-expression before '>' token
   41 |       vecotr<vector<int>>dp_(si[nw] + 1, vector<int>(5050, -1));
      |                        ^~
a.cc:41:26: error: 'dp_' was not declared in this scope; did you mean 'dp'?
   41 |       vecotr<vector<int>>dp_(si[nw] + 1, vector<int>(5050, -1));
      |                          ^~~
      |                          dp
Language: C++

#include<bits/stdc++.h>
#include<queue>
using namespace std;
void cha(int &a, int b) {
  if (b == -1) return;
  if (a == -1 || a > b) {
    a = b;
  }
}
int main () {
  int N;
  cin >> N;
  vector<vector<int>>son(N + 1, vector<int>(N + 1));
  vector<int>si(N + 1, 0);
  for (int i = 2; i <= N; i ++) {
    int a;
    cin >> a;
    son[a][si[a]] = i;
    si[a] ++;
  }
  vector<int>X(N + 1);
  for (int i = 1; i <= N; i ++) cin >> X[i];
  vector<int>per;
  queue<int>que;
  que.push(1);
  per.push_back(1);
  while(!que.empty()) {
    int u = que.front();
    for (int i = 0; i < si[u]; i ++) {
      int ne = son[u][i];
      per.push_back(ne);
      que.push(ne);
    }
    que.pop();
  }
  int dp[1010];
  for (int i = N - 1; i >= 0; i --) {
    int nw = per[i];
    if (!si[nw]) dp[nw] = 0;
    else {
      vector<int>dp_(5050, -1);
      dp_[0] = 0;
      for (int i_ = 0; i_ < si[nw]; i_ ++) {
        int so = son[nw][i_];
        for (int j = X[nw]; j >= 0; j --) {
          if (j + X[so] <= X[nw]) {
            cha(dp_[j + X[so]], dp_[j] + dp[so]);
          }
          if (j + dp[so] <= X[nw]) {
            cha(dp_[j + dp[so]], dp_[j] + X[so]);
          }
        }
      }
      dp[nw] = -1;
      for (int i_ = 0; i_ <= X[nw]; i_ ++) {
        cha(dp[nw], dp_[i])
      }
      if (dp[nw] == -1) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "POSSIBLE" << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:56:28: error: expected ';' before '}' token
   56 |         cha(dp[nw], dp_[i])
      |                            ^
      |                            ;
   57 |       }
      |       ~