Submission #372658

# Submission time Handle Problem Language Result Execution time Memory
372658 2021-03-01T08:46:37 Z hivakarami Beads and wires (APIO14_beads) C++14
0 / 100
1 ms 492 KB
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;
#define f first
#define s second
 
const int N = 100 + 100;
const int K = 1000 + 100;
const ll mod = 998244353;
const ll inf = 1e9 + 100;

ll dp[2][N], w[N][N], par[N];
vector<int> adj[N];
int n;

void dfs(int u)
{
	dp[1][u] = 0;
	for(auto x : adj[u])
	{
		if(x != par[u])
		{
			par[x] = u;
			dfs(x);
			dp[1][u] += min(dp[1][x] + w[x][u], dp[2][x]);
		}
	}
	
	dp[2][u] = inf;
	for(auto x : adj[u])
	{
		if(x != par[u])
		{
			ll mn = min(dp[1][x] + w[x][u], dp[2][x]);
			dp[2][u] = min(dp[2][u], dp[1][u] - mn + dp[1][x]);
		}
	}
	
	//cout << u << ' ' << dp[1][u] << ' ' << dp[2][u] << endl;
}


inline void cl()
{
	for(int i = 0; i < n; i++)
		par[i] = i;
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);	
	
	cin >> n;
	ll sum = 0;
	for(int i = 0; i < n-1; i++)
	{
		int x, y;
		cin >> x >> y;
		x--; y--;
		cin >> w[x][y];
		adj[x].push_back(y);
		adj[y].push_back(x);
		w[y][x] = w[x][y];
		sum += w[x][y];
	}
	
	ll ans = inf;
	
	for(int i = 0; i < n; i++)
	{
		cl();
		dfs(i);
		ans = min(ans, dp[1][i]);
	}	
		
	cout << sum - ans << endl;
	
	
		
		
	return 0;
}





Compilation message

beads.cpp: In function 'void dfs(int)':
beads.cpp:32:6: warning: array subscript 2 is above array bounds of 'll [2][200]' {aka 'long long int [2][200]'} [-Warray-bounds]
   32 |  dp[2][u] = inf;
      |  ~~~~^
beads.cpp:15:4: note: while referencing 'dp'
   15 | ll dp[2][N], w[N][N], par[N];
      |    ^~
beads.cpp:37:40: warning: array subscript 2 is above array bounds of 'll [2][200]' {aka 'long long int [2][200]'} [-Warray-bounds]
   37 |    ll mn = min(dp[1][x] + w[x][u], dp[2][x]);
      |                                    ~~~~^
beads.cpp:38:23: warning: array subscript 2 is above array bounds of 'll [2][200]' {aka 'long long int [2][200]'} [-Warray-bounds]
   38 |    dp[2][u] = min(dp[2][u], dp[1][u] - mn + dp[1][x]);
      |                   ~~~~^
beads.cpp:38:8: warning: array subscript 2 is above array bounds of 'll [2][200]' {aka 'long long int [2][200]'} [-Warray-bounds]
   38 |    dp[2][u] = min(dp[2][u], dp[1][u] - mn + dp[1][x]);
      |    ~~~~^
beads.cpp:15:4: note: while referencing 'dp'
   15 | ll dp[2][N], w[N][N], par[N];
      |    ^~
beads.cpp:28:44: warning: array subscript 2 is above array bounds of 'll [2][200]' {aka 'long long int [2][200]'} [-Warray-bounds]
   28 |    dp[1][u] += min(dp[1][x] + w[x][u], dp[2][x]);
      |                                        ~~~~^
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -