Submission #369912

# Submission time Handle Problem Language Result Execution time Memory
369912 2021-02-22T18:03:15 Z azberjibiou Meetings (JOI19_meetings) C++17
7 / 100
317 ms 1492 KB
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
const int mxN=2020;
vector <int> v[mxN], g[mxN];
bool Chk[mxN];
bool used[mxN];
int sub[mxN];
int msub[mxN];
int f[mxN], invf[mxN];
bool cmp1(int a, int b)
{
    return sub[a]>sub[b];
}
void dfs1(int now, int pre)
{
    //printf("now=%d\n", now);
    sub[now]=1;
    msub[now]=-1;
    for(int nxt : v[now])
    {
        if(Chk[nxt] || nxt==pre)    continue;
        dfs1(nxt, now);
        sub[now]+=sub[nxt];
        if(msub[now]==-1)   msub[now]=nxt;
        else if(sub[msub[now]]<sub[nxt])   msub[now]=nxt;
    }
}
void Solve(int N) {
    for(int i=0;i<N;i++)    f[i]=i;
    random_shuffle(f, f+N);
    for(int i=0;i<N;i++)    invf[f[i]]=i;
    v[0].push_back(1);
    v[1].push_back(0);
    for(int i=2;i<N;i++)
    {
        if(used[i]) continue;
        int root=1;
        for(int j=0;j<N;j++)    Chk[j]=false;
        int cnt=0;
        while(true)
        {
            cnt++;
            assert(cnt<=14);
            dfs1(root, -1);
            int cent=root;
            while(msub[cent]!=-1 && sub[msub[cent]]*2>sub[cent])   cent=msub[cent];
            for(int nxt : v[cent])
            {
                if(Chk[nxt] || sub[nxt]<sub[cent])   continue;
                sub[nxt]=sub[root]-sub[cent];
            }
            //printf("cent=%d\n", cent);
            //for(int j=0;j<i;j++)    printf("Chk[%d]=%d\n", j, Chk[j]);
            /*for(int j=0;j<i;j++)
            {
                printf("%d: ", j);
                for(int nxt : g[j]) printf("%d ", nxt);
                printf("\n");
            }*/
            g[cent].clear();
            for(int nxt : v[cent])  if(!Chk[nxt])   g[cent].push_back(nxt);
            sort(g[cent].begin(), g[cent].end(), cmp1);
            if(g[cent].empty())
            {
                //printf("here");
                v[cent].push_back(i);
                v[i].push_back(cent);
                break;
            }
            bool par=true;
            bool flag=false;
            for(int j=0;j<g[cent].size();j++)
            {
                int nxt=g[cent][j];
                int res=invf[Query(f[cent], f[nxt], f[i])];
                if(res!=cent)
                {
                    par=false;
                    if(res==i)
                    {
                        //printf("s1");
                        for(int k=0;k<v[cent].size();k++)
                        {
                            if(v[cent][k]==nxt)
                            {
                                v[cent][k]=i;
                                break;
                            }
                        }
                        for(int k=0;k<v[nxt].size();k++)
                        {
                            if(v[nxt][k]==cent)
                            {
                                v[nxt][k]=i;
                                break;
                            }
                        }
                        v[i].push_back(cent);
                        v[i].push_back(nxt);
                        flag=true;
                    }
                    else if(res==nxt)
                    {
                        //printf("s2");
                        root=nxt;
                        Chk[cent]=true;
                        //assert(cent!=nxt);
                    }
                    else
                    {
                        //printf("s3");
                        for(int k=0;k<v[cent].size();k++)    {if(v[cent][k]==nxt) {v[cent][k]=res;   break;}}
                        for(int k=0;k<v[nxt].size();k++)    {if(v[nxt][k]==cent) {v[nxt][k]=res;    break;}}
                        v[res].push_back(cent);
                        v[res].push_back(nxt);
                        v[i].push_back(res);
                        v[res].push_back(i);
                        used[res]=true;
                        flag=true;
                    }
                    break;
                }
            }
            if(flag)    break;
            if(par)
            {
                v[cent].push_back(i);
                v[i].push_back(cent);
                break;
            }
        }
    }
    for(int i=0;i<N;i++)
    {
        for(int nxt : v[i])
        {
            if(f[nxt]>f[i]) Bridge(f[i], f[nxt]);
        }
    }
}

Compilation message

meetings.cpp: In function 'void Solve(int)':
meetings.cpp:75:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |             for(int j=0;j<g[cent].size();j++)
      |                         ~^~~~~~~~~~~~~~~
meetings.cpp:85:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |                         for(int k=0;k<v[cent].size();k++)
      |                                     ~^~~~~~~~~~~~~~~
meetings.cpp:93:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |                         for(int k=0;k<v[nxt].size();k++)
      |                                     ~^~~~~~~~~~~~~~
meetings.cpp:115:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |                         for(int k=0;k<v[cent].size();k++)    {if(v[cent][k]==nxt) {v[cent][k]=res;   break;}}
      |                                     ~^~~~~~~~~~~~~~~
meetings.cpp:116:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |                         for(int k=0;k<v[nxt].size();k++)    {if(v[nxt][k]==cent) {v[nxt][k]=res;    break;}}
      |                                     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 0 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 0 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Runtime error 1 ms 876 KB Execution killed with signal 6
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 0 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Runtime error 1 ms 876 KB Execution killed with signal 6
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 317 ms 1492 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -