Submission #895677

# Submission time Handle Problem Language Result Execution time Memory
895677 2023-12-30T13:34:00 Z thunopro Designated Cities (JOI19_designated_cities) C++14
6 / 100
103 ms 20088 KB
#include<bits/stdc++.h>
using namespace std ; 
#define ll long long 
#define maxn 200009 
#define fi first 
#define se second 
#define pb push_back 
#define left id<<1 
#define right id<<1|1 
#define re exit(0); 
#define _lower(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()+1  

const int mod = 1e9+7 ; 
const int INF = 1e9 ; 
const int LOG = 18 ; 

typedef vector<int> vi ; 
typedef pair<int,int> pii ; 
typedef vector<ll> vl ; 
typedef vector<pii> vii ; 
 
void add ( int &a , int b ) 
{
	a += b ;
	if ( a < 0 ) a += mod ; 
	if ( a >= mod ) a -= mod ; 
}

template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; } 
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; } 

void rf () 
{
	freopen ("bai1.inp","r",stdin) ; 
//	freopen ("bai1.out","w",stdout) ; 
}

int _pow ( int a , int n ) 
{
	if ( n == 0 ) return 1 ; 
	int res = _pow (a,n/2) ; 
	if ( n % 2 ) return 1ll*res*res%mod*a%mod ; 
	else return 1ll*res*res%mod ; 
}

int n , nq ;

vii adjList [maxn] ; 

int sz [maxn] , dep [maxn] ; 

void dfs_sub1 ( int u = 1 , int par = 1 ) 
{
	for ( auto x : adjList [u] ) 
	{
		int v = x.fi , w = x.se ; 
		if ( v == par ) continue ;
		dep [v] = dep [u] + 1 ;  
		dfs_sub1 (v,u) ; 
		sz [u] += sz [v] ; 
	}
}

void sub1 () 
{
	ll total = 0 ; 
	for ( int i = 1 ; i <= n ; i ++ ) for ( auto x : adjList [i] ) total += x.se ; 
	
	ll res [n+2] ; 
	memset ( res , 0x3f , sizeof res ) ; 
	
	for ( int mask = 1 ; mask < (1<<n) ; mask ++ ) 
	{
		for ( int i = 0 ; i < n ; i ++ ) 
		{
			if ( mask >> i & 1 ) sz [i+1] = 1 ; 
			else sz [i+1] = 0 ; 
		}
		dfs_sub1 () ;
		ll sum = total ; 
		int total_sz = __builtin_popcount (mask) ; 
		for ( int i = 1 ; i <= n ; i ++ ) 
		{
			for ( auto x : adjList [i] ) 
			{
				int v = x.fi , w = x.se ; 
				if ( dep [v] > dep [i] ) sum -= ( sz [v] > 0 ) * w ; 
				else sum -= ((total_sz-sz[i]) > 0) * w ;  
			}
		} 
		chkmin (res[total_sz],sum) ; 
	}
	
	cin >> nq ; 
	while ( nq -- ) 
	{
		int E ; cin >> E ; 
		cout << res [E] << "\n" ;
	}
}
int main () 
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0) ; 
//	rf () ; 
	
	cin >> n ; 
	for ( int i = 1 ; i < n ; i ++ ) 
	{
		int u , v , cost_u , cost_v ; 
		cin >> u >> v >> cost_u >> cost_v ; 
		adjList [u] . pb ({v,cost_u}) ; 
		adjList [v] . pb ({u,cost_v}) ; 
	}
	
	if ( n <= 16 ) sub1 () ; 
}

// range , error , check speical , ... 
// find key , find key 
//'-std=c++11' stay hard 
// there is no tomorrow 

Compilation message

designated_cities.cpp: In function 'void dfs_sub1(int, int)':
designated_cities.cpp:56:18: warning: unused variable 'w' [-Wunused-variable]
   56 |   int v = x.fi , w = x.se ;
      |                  ^
designated_cities.cpp: In function 'void rf()':
designated_cities.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 13 ms 6540 KB Output is correct
3 Correct 11 ms 6488 KB Output is correct
4 Correct 10 ms 6492 KB Output is correct
5 Correct 10 ms 6492 KB Output is correct
6 Correct 14 ms 6492 KB Output is correct
7 Correct 14 ms 6488 KB Output is correct
8 Correct 12 ms 6492 KB Output is correct
9 Correct 10 ms 6492 KB Output is correct
10 Correct 11 ms 6492 KB Output is correct
11 Correct 10 ms 6540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 94 ms 20088 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 103 ms 20060 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 13 ms 6540 KB Output is correct
3 Correct 11 ms 6488 KB Output is correct
4 Correct 10 ms 6492 KB Output is correct
5 Correct 10 ms 6492 KB Output is correct
6 Correct 14 ms 6492 KB Output is correct
7 Correct 14 ms 6488 KB Output is correct
8 Correct 12 ms 6492 KB Output is correct
9 Correct 10 ms 6492 KB Output is correct
10 Correct 11 ms 6492 KB Output is correct
11 Correct 10 ms 6540 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Incorrect 2 ms 6556 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 94 ms 20088 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 13 ms 6540 KB Output is correct
3 Correct 11 ms 6488 KB Output is correct
4 Correct 10 ms 6492 KB Output is correct
5 Correct 10 ms 6492 KB Output is correct
6 Correct 14 ms 6492 KB Output is correct
7 Correct 14 ms 6488 KB Output is correct
8 Correct 12 ms 6492 KB Output is correct
9 Correct 10 ms 6492 KB Output is correct
10 Correct 11 ms 6492 KB Output is correct
11 Correct 10 ms 6540 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Incorrect 94 ms 20088 KB Output isn't correct
14 Halted 0 ms 0 KB -