Submission #146817

# Submission time Handle Problem Language Result Execution time Memory
146817 2019-08-26T09:34:07 Z Bodo171 Split the Attractions (IOI19_split) C++14
0 / 100
102 ms 15792 KB
#include "split.h"
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int nmax=100005;
pair<int,int> col[5];
vector<int> res;
vector<int> v[nmax],ad[nmax];
int l[nmax],r[nmax],rep[nmax],w[nmax],pond[nmax],big[nmax],q[nmax],viz[nmax],valid[nmax],tt[nmax];
int nr,x,sum,p,u,i,j,k,nod,A,act,gasit,n,cen;
void dfs(int x)
{
    rep[++nr]=x;l[x]=nr;
    w[x]=1;
    for(int i=0;i<v[x].size();i++)
        if(!w[v[x][i]])
    {
        dfs(v[x][i]);
        w[x]+=w[v[x][i]];
        big[x]=max(big[x],w[v[x][i]]);
    }
    r[x]=nr;
}
void bfs(int x)
{
    q[u=1]=x;sum=pond[x];viz[x]=1;
    for(p=1;p<=u;p++)
    {
        x=q[p];
        for(i=0;i<ad[x].size();i++)
        {
            nod=ad[x][i];
            if(!viz[nod])
            {
                viz[nod]=1;
                sum+=pond[nod];
                if(sum>=A)
                {
                    for(j=1;j<=u;j++)
                    {
                        act=q[j];
                        for(k=l[act];k<=r[act];k++)
                            valid[rep[k]]=1;
                        gasit=1;
                        return;
                    }
                }
            }
        }
    }
}
void coloreaza(int cate,int C)
{
    int start=0;
    for(i=0;i<n;i++)
    {
        if(valid[i])
            start=i;
        viz[i]=0;
    }
    q[u=1]=start;
    for(p=1;p<=u;p++)
    {
        x=q[p];
        res[x]=C;
        if(p==cate) return;
        for(i=0;i<v[x].size();i++)
            if(valid[v[x][i]]&&(!viz[v[x][i]]))
            {
                q[++u]=v[x][i];
                viz[v[x][i]]=1;
            }
    }
}
vector<int> find_split(int N, int a, int b, int c, vector<int> p, vector<int> q) {
    n=N;
    res.resize(n);
    col[0]={a,1};
    col[1]={b,2};
    col[2]={c,3};
    sort(col,col+3);
    A=col[0].first;
    int m=p.size();
    for(i=0;i<m;i++)
    {
        v[p[i]].push_back(q[i]);
        v[q[i]].push_back(p[i]);
    }

    dfs(0);
    for(i=0;i<n;i++)
        if(n-w[x]<=n/2&&big[x]<=n/2)
           cen=x;
    for(i=1;i<=n;i++)
        w[i]=0;
    nr=0;
    dfs(cen);
    for(i=0;i<v[cen].size();i++)
    {
        x=v[cen][i];
        for(j=l[x];j<=r[x];j++)
        {
            nod=rep[j];
            tt[nod]=x;
        }
        pond[x]=w[x];
        if(pond[x]>=A&&(!gasit))
        {
            gasit=1;
            for(j=l[x];j<=r[x];j++)
            {
                valid[rep[j]]=1;
            }
        }
    }
    for(i=0;i<m;i++)
    {
        ad[tt[p[i]]].push_back(tt[q[i]]);
        ad[tt[q[i]]].push_back(tt[p[i]]);
    }
    if(!gasit)
    for(int it=0;it<v[cen].size();it++)
    {
        if(!viz[v[cen][it]])
            bfs(v[cen][it]);
    }
    if(!gasit) return res;
    coloreaza(col[0].first,col[0].second);
    for(i=0;i<n;i++)
        valid[i]^=1;
    coloreaza(col[1].first,col[1].second);
    for(i=0;i<n;i++)
        if(!res[i])
          res[i]=col[2].second;
	return res;
}

Compilation message

split.cpp: In function 'void dfs(int)':
split.cpp:16:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[x].size();i++)
                 ~^~~~~~~~~~~~
split.cpp: In function 'void bfs(int)':
split.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<ad[x].size();i++)
                 ~^~~~~~~~~~~~~
split.cpp: In function 'void coloreaza(int, int)':
split.cpp:68:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<v[x].size();i++)
                 ~^~~~~~~~~~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:99:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<v[cen].size();i++)
             ~^~~~~~~~~~~~~~
split.cpp:123:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int it=0;it<v[cen].size();it++)
                  ~~^~~~~~~~~~~~~~
split.cpp:133:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(i=0;i<n;i++)
     ^~~
split.cpp:136:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  return res;
  ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5084 KB ok, correct split
2 Correct 7 ms 5112 KB ok, correct split
3 Correct 6 ms 5112 KB ok, correct split
4 Correct 7 ms 5112 KB ok, correct split
5 Correct 6 ms 5112 KB ok, correct split
6 Incorrect 7 ms 5112 KB invalid split: #1=1, #2=19, #3=80
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5112 KB ok, correct split
2 Correct 7 ms 5032 KB ok, correct split
3 Incorrect 7 ms 5112 KB invalid split: #1=1, #2=1, #3=3
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB ok, correct split
2 Incorrect 102 ms 15792 KB invalid split: #1=19999, #2=2, #3=79999
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5116 KB ok, correct split
2 Correct 7 ms 4984 KB ok, no valid answer
3 Correct 6 ms 5112 KB ok, correct split
4 Incorrect 6 ms 5112 KB invalid split: #1=1, #2=3, #3=7
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5084 KB ok, correct split
2 Correct 7 ms 5112 KB ok, correct split
3 Correct 6 ms 5112 KB ok, correct split
4 Correct 7 ms 5112 KB ok, correct split
5 Correct 6 ms 5112 KB ok, correct split
6 Incorrect 7 ms 5112 KB invalid split: #1=1, #2=19, #3=80
7 Halted 0 ms 0 KB -