Submission #110623

# Submission time Handle Problem Language Result Execution time Memory
110623 2019-05-11T15:02:27 Z The_Wolfpack Friend (IOI14_friend) C++14
Compilation error
0 ms 0 KB
include <bits/stdc++.h>
using namespace std;
const int NMAX=2007;

int cnt[3],vis[NMAX],w[NMAX],dp[NMAX][2];    
vector<int> g[NMAX];

int ans=0;
void dfs(int son, int par)
{
    vis[son]=1;
    ans=max(ans,w[son]);
    for(int i:g[son]) if(!vis[i]) dfs(i,son);
}

void dfs1(int son,int par)
{
    vis[son]=1;
    dp[son][1]=w[son];
    for(int i:g[son])
    {
        if(vis[i]) continue; 
        dfs1(i,son);
        dp[son][0]+=max(dp[i][0],dp[i][1]);
        dp[son][1]+=dp[i][0];
    }
}

int findSample(int n, int confidence[], int host[], int protocol[])
{
    //cin>>n; 
    //for(int i=0;i<n;i++) cin>>confidence[i], w[i]=confidence[i];
    for(int i=0;i<n;i++) w[i]=confidence[i];
    for(int i=1;i<n;i++) 
    {
        //cin>>host[i]>>protocol[i];
        int tmp=protocol[i];
        if(tmp==0)
        {
            cnt[0]++;
            g[host[i]].push_back(i);
            g[i].push_back(host[i]);
        }
        if(tmp==1)
        {
            cnt[1]++;
            for(int j:g[host[i]])
            {
                g[i].push_back(j);
                g[j].push_back(i);     
            }
        }
        else
        {
            cnt[2]++;
            g[host[i]].push_back(i);
            g[i].push_back(host[i]);
            for(int j:g[host[i]])
            {
                if(i==j) continue; 
                g[i].push_back(j);
                g[j].push_back(i);     
            }
        }
    }
    if(n<=10)
    {
        int res=0; 
        for(int mask=1;mask<(1<<n);mask++)
        {
            vector<int> tmp;
            for(int i=0;i<n;i++) if(mask&(1<<i)) tmp.push_back(i);
            int ok=1;
            
            for(int i:tmp)
            {
                for(int j:tmp)
                {
                    if(i==j) continue; 
                    for(int t:g[i]) if(t==j) ok=0;
                }
            }
            
            int ans=0;
            if(ok) for(int i:tmp) ans+=confidence[i];
            if(ok) res=max(res,ans);
        }
        return res;
    }
    if(cnt[2]==n-1)
    {
        int res=0;
        ans=0;
        for(int i=0;i<n;i++) if(!vis[i]){dfs(i,0); res+=ans;}
        return res;
    }
    if(cnt[1]==n-1)
    {
        int res=0;
        for(int i=0;i<n;i++) res+=w[i];
        return res;
    }
    if(cnt[0]==n-1)
    {
        int res=0;
        for(int i=0;i<n;i++) if(!vis[i]){dfs1(i,0); res+=max(dp[i][0],dp[i][1]);}
        return res;
    }
}

Compilation message

friend.cpp:1:1: error: 'include' does not name a type; did you mean '__has_include'?
 include <bits/stdc++.h>
 ^~~~~~~
 __has_include
friend.cpp:6:1: error: 'vector' does not name a type
 vector<int> g[NMAX];
 ^~~~~~
friend.cpp: In function 'void dfs(int, int)':
friend.cpp:12:9: error: 'max' was not declared in this scope
     ans=max(ans,w[son]);
         ^~~
friend.cpp:13:15: error: 'g' was not declared in this scope
     for(int i:g[son]) if(!vis[i]) dfs(i,son);
               ^
friend.cpp: In function 'void dfs1(int, int)':
friend.cpp:20:15: error: 'g' was not declared in this scope
     for(int i:g[son])
               ^
friend.cpp:24:21: error: 'max' was not declared in this scope
         dp[son][0]+=max(dp[i][0],dp[i][1]);
                     ^~~
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:41:13: error: 'g' was not declared in this scope
             g[host[i]].push_back(i);
             ^
friend.cpp:47:23: error: 'g' was not declared in this scope
             for(int j:g[host[i]])
                       ^
friend.cpp:56:13: error: 'g' was not declared in this scope
             g[host[i]].push_back(i);
             ^
friend.cpp:71:13: error: 'vector' was not declared in this scope
             vector<int> tmp;
             ^~~~~~
friend.cpp:71:20: error: expected primary-expression before 'int'
             vector<int> tmp;
                    ^~~
friend.cpp:72:50: error: 'tmp' was not declared in this scope
             for(int i=0;i<n;i++) if(mask&(1<<i)) tmp.push_back(i);
                                                  ^~~
friend.cpp:75:23: error: 'tmp' was not declared in this scope
             for(int i:tmp)
                       ^~~
friend.cpp:77:27: error: unable to deduce 'auto&&' from 'tmp'
                 for(int j:tmp)
                           ^~~
friend.cpp:80:31: error: 'g' was not declared in this scope
                     for(int t:g[i]) if(t==j) ok=0;
                               ^
friend.cpp:85:30: error: 'tmp' was not declared in this scope
             if(ok) for(int i:tmp) ans+=confidence[i];
                              ^~~
friend.cpp:86:24: error: 'max' was not declared in this scope
             if(ok) res=max(res,ans);
                        ^~~
friend.cpp:86:24: note: suggested alternative: 'mask'
             if(ok) res=max(res,ans);
                        ^~~
                        mask
friend.cpp:106:58: error: 'max' was not declared in this scope
         for(int i=0;i<n;i++) if(!vis[i]){dfs1(i,0); res+=max(dp[i][0],dp[i][1]);}
                                                          ^~~
friend.cpp:109:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^