Submission #124721

# Submission time Handle Problem Language Result Execution time Memory
124721 2019-07-03T19:05:35 Z vex Designated Cities (JOI19_designated_cities) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define maxn 200005
#define pii pair<int,int>
#define sus first
#define w second
using namespace std;

/*** 20:50***/

int n;
vector<pii>adj[maxn];
long long dp[maxn];

long long down[maxn],up[maxn];
void dfs(int v,int p,int tez)
{
	down[v]=0LL;
	for(auto x:adj[v])
	{
		if(x.sus!=p)
		{
			down[v]+=x.w;
			dfs(x,v,x.w);
			down[v]+=down[x];
		}
	}
	
	up[v]=0LL;	
	for(auto x:adj[v])
	{
		if(x.sus==p)
		{
			up[v]+=up[p];
			up[v]+=x.w;
			up[v]+=down[p]-tez-down[v];
		}
	}
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		
		adj[a].push_back(b,c);
		adj[b].push_back(a,c);
	}
	
	dfs(1,1,0);
	
	long long dp[1]=INF;
	for(int i=1;i<=n;i++)
	{
		dp[1]=min(dp[1],up[i]+down[i]);
	}
	
	
	
	
	
	
	int q;
	cin>>q;
	while(q>0)
	{
		int e;
		cin>>e;
		cout<<dp[e]<<endl;
		q--;
	}
	
	return 0;
}

Compilation message

designated_cities.cpp: In function 'void dfs(int, int, int)':
designated_cities.cpp:23:15: error: cannot convert 'std::pair<int, int>' to 'int' for argument '1' to 'void dfs(int, int, int)'
    dfs(x,v,x.w);
               ^
designated_cities.cpp:24:17: error: no match for 'operator[]' (operand types are 'long long int [200005]' and 'std::pair<int, int>')
    down[v]+=down[x];
                 ^
designated_cities.cpp: In function 'int main()':
designated_cities.cpp:52:23: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(int&, int&)'
   adj[a].push_back(b,c);
                       ^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from designated_cities.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:939:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(const value_type& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:939:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/7/bits/stl_vector.h:953:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(value_type&& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:953:7: note:   candidate expects 1 argument, 2 provided
designated_cities.cpp:53:23: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(int&, int&)'
   adj[b].push_back(a,c);
                       ^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from designated_cities.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:939:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(const value_type& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:939:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/7/bits/stl_vector.h:953:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(value_type&& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:953:7: note:   candidate expects 1 argument, 2 provided
designated_cities.cpp:58:18: error: 'INF' was not declared in this scope
  long long dp[1]=INF;
                  ^~~
designated_cities.cpp:58:18: note: suggested alternative: 'SING'
  long long dp[1]=INF;
                  ^~~
                  SING