Submission #105810

# Submission time Handle Problem Language Result Execution time Memory
105810 2019-04-15T06:31:51 Z TuGSGeReL Friend (IOI14_friend) C++14
35 / 100
4 ms 512 KB
#include "friend.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back()
#define ss second
#define ff first
#define mt make_tuple
#define pof pop_front()
#define fbo find_by_order
#define ook order_of_key
 
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
 
int used[2001], pre[3], dp[2001][2], idx, par[2001], fl[2001][2001];
vector <int> edg[2001];
pair<int, int> p[1001];
 
int solve1(int n, int confidence[], int host[], int protocol[])
{
 
	int ans = 0;

	for (int i = 1; i < n; i++)
	{
    	if ( !protocol[i] )
    	{
    		edg[i].pub(host[i]);
			edg[host[i]].pub(i);
    	} else if ( protocol[i] == 1 )
    	{
    		for (int j = 0; j < edg[host[i]].size(); j++)
    		{
    			edg[edg[host[i]][j]].pub(i);
    			edg[i].pub(edg[host[i]][j]);
    		}
    	} else {
    		
			for (int j = 0; j < edg[host[i]].size(); j++)
    		{
    			edg[i].pub(edg[host[i]][j]);
				edg[edg[host[i]][j]].pub(i);
    		}
 	
			edg[i].pub(host[i]);
			edg[host[i]].pub(i);
		}
	}
 
	for (int i = 0; i < (1 << n); i++)
	{
		memset(used, 0, sizeof used);
		bool boo = 0;
		int res = 0;
 
		for (int j = 0; j < n; j++)
		{
    		if ( i & (1 << j) )
    		{
    			for ( auto x : edg[j] )
        			if ( used[x] )
            			boo = 1;
 
        	res += confidence[j];
        	used[j] = 1;
			}
		}

		if ( !boo )
			ans = max(ans, res);
	}
 
	return ans;
}
 
void dfs(int u, int pra)
{
	bool boo = 1;
	for (auto x : edg[u])
		if ( x != pra )
    		dfs(x, u), boo = 0;
 
	if ( pra != -1 )
	{
		dp[pra][0] += max(dp[u][1], dp[u][0]);
		dp[pra][1] += dp[u][0];
	}
}
 
bool bfs(int u)
{
	memset(used, 0, sizeof used);
	used[u] = 1;
	par[u] = -1;
	queue<int>q;
	q.push(u);
	
	while (!q.empty())
	{
		u = q.front();
		q.pop();
 
		for (int i = 0; i <= idx; i++)
    	{
			if ( fl[u][i] && !used[i] )
    		{
				used[i] = 1;
				par[i] = u;
				q.push(i);
    		}
		}
	}
 
	if ( used[idx] )
		return 1;
 
	return 0;
}
 
int findSample(int n,int confidence[],int host[],int protocol[]){
 
//	if ( n <= 10 )
//		return solve1(n, confidence, host, protocol);
 
	for (int i = 1; i < n; i++)
		pre[protocol[i]]++;
 
	if ( pre[1] == n - 1 )
	{
    	int ans = 0;
 
		for (int i = 0; i < n; i++)
    		ans += confidence[i];
 
		return ans;
	}
 
	if ( pre[2] == n - 1 )
	{
		int ans = 0;
 
		for (int i = 0; i < n; i++)
		ans = max(ans, confidence[i]);
 
		return ans;
	}
 
	if ( pre[0] == n - 1 )
	{
		for (int i = 1; i < n; i++)
		{
    		edg[host[i]].pub(i);
    		edg[i].pub(host[i]);
    	}

    	for (int i = 0; i < n; i++)
			dp[i][1] = confidence[i];
 
		dfs(0, -1);
 
	    return max(dp[0][0], dp[0][1]);
	}
	
	p[0].ss = 0;
	
	for (int i = 1; i < n - 1; i++)
	{
		p[i].ff = ++idx;
		p[i].ss = ++idx;
		fl[p[i].ff][p[i].ss] = 1;
	}
	
	p[n - 1].ff = ++idx;
	
	for (int i = 1; i < n; i++)
	{
		if ( !protocol[i] )
		{
			edg[i].pub(host[i]);
    		edg[host[i]].pub(i);
    		fl[p[host[i]].ss][p[i].ff] = 1;
    	} else {
			for (auto x : edg[host[i]])
    		{
				fl[p[x].ss][p[i].ff] = 1;
        		edg[x].pub(i);
        		edg[i].pub(x);
			}
    	}
	}
	
	int ans = 0;
 
	while (bfs(0))
	{
    	for (int i = idx; par[i] != -1; i = par[i])
    		fl[par[i]][i]--, fl[i][par[i]]++;
		
		ans++;
	}
 
	return ans;
}

Compilation message

friend.cpp: In function 'int solve1(int, int*, int*, int*)':
friend.cpp:40:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int j = 0; j < edg[host[i]].size(); j++)
                       ~~^~~~~~~~~~~~~~~~~~~~~
friend.cpp:47:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < edg[host[i]].size(); j++)
                    ~~^~~~~~~~~~~~~~~~~~~~~
friend.cpp: In function 'void dfs(int, int)':
friend.cpp:86:7: warning: variable 'boo' set but not used [-Wunused-but-set-variable]
  bool boo = 1;
       ^~~
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:204:6: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
      for (int i = idx; par[i] != -1; i = par[i])
      ^~~
friend.cpp:207:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   ans++;
   ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 356 KB Output is correct
7 Incorrect 3 ms 384 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 356 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Incorrect 2 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -