Submission #1077586

# Submission time Handle Problem Language Result Execution time Memory
1077586 2024-08-27T08:06:49 Z vnm06 Amusement Park (JOI17_amusement_park) C++14
10 / 100
18 ms 4652 KB
#include "Joi.h"
#include<bits/stdc++.h>

using namespace std;

long long _x;
int _n, _m;
vector<int> _gr[10005];
int _par[10005], _dpt[10005], _root;
bool _used[10005];

queue<int> _qu;

int _br=0;
void _euler_tour(int v)
{
  MessageBoard(v, bool(_x&((long long)1<<(_br%60))));
  _used[v]=1;
  int _brs=_gr[v].size();
  for(int i=0; i<_brs; i++)
  {
    int nv=_gr[v][i];
    if(_used[nv]) continue;
    _br++;
    _euler_tour(nv);
  }
}

void _find_diam()
{
  _qu.push(0);
  _used[0]=1;
  int lastv;


  while(!_qu.empty())
  {
    lastv=_qu.front();
    _qu.pop();
    int _brs=_gr[lastv].size();
    for(int i=0; i<_brs; i++)
    {
      int nv=_gr[lastv][i];
      if(!_used[nv])
      {
        _used[nv]=1;
        _qu.push(nv);
      }
    }
  }
  for(int i=0; i<_n; i++) _used[i]=0;
  _used[lastv]=1;
  _par[lastv]=lastv;
  _root=lastv;
  _qu.push(lastv);

  while(!_qu.empty())
  {
    lastv=_qu.front();
    _qu.pop();
    int _brs=_gr[lastv].size();
    for(int i=0; i<_brs; i++)
    {
      int nv=_gr[lastv][i];
      if(!_used[nv])
      {
        _used[nv]=1;
        _par[nv]=lastv;
        _dpt[nv]=_dpt[lastv]+1;
        _qu.push(nv);
      }
    }
  }

  if(_dpt[lastv]>=59)
  {
    for(int i=0; i<_n; i++) {MessageBoard(i, bool(_x&((long long)1<<(_dpt[i]%60)))); /**cout<<((long long)1<<(_dpt[i]%60))<<endl;*/}
    return;
  }

  int lng=_dpt[lastv]+1, nr=lastv;
  for(int i=1; i<lng/2; i++) nr=_par[nr];
  for(int i=0; i<_n; i++) _used[i]=0;
  _euler_tour(nr);

}

void Joi(int N, int M, int A[], int B[], long long X, int T) 
{
  _n=N;
  _m=M;
  _x=X;
  for(int i=0; i<M; i++)
  {
    _gr[A[i]].push_back(B[i]);
    _gr[B[i]].push_back(A[i]);
  }
  _find_diam();
}
#include "Ioi.h"
#include<bits/stdc++.h>

using namespace std;

long long x=0;
int n, m, p;
vector<int> gr[10005];
int par[10005], dpt[10005], root;
bool used[10005];
long long tval[10005];
long long tpos[10005];
int destn[10005];

queue<int> qu;

int br=0;
void euler_tour(int v)
{
  tpos[v]=br%60;
  used[v]=1;
  int brs=gr[v].size();
  for(int i=0; i<brs; i++)
  {
    int nv=gr[v][i];
    if(used[nv]) continue;
    par[nv]=v;
    br++;
    euler_tour(nv);
  }
}

bool prikl=0;

void euler_tour2(int v)
{
  if(br>=60) return;
  x|=(tval[v]<<tpos[v]);
  used[v]=1;
  int brs=gr[v].size();
  for(int i=0; i<brs; i++)
  {
    int nv=gr[v][i];
    if(used[nv]) continue;
    br++;
    tval[nv]=Move(nv);
    euler_tour2(nv);
    if(br>=60) return;
  }
  Move(par[v]);
}

long long find_diam()
{
  qu.push(0);
  used[0]=1;
  int lastv;
  while(!qu.empty())
  {
    lastv=qu.front();
    qu.pop();
    int brs=gr[lastv].size();
    for(int i=0; i<brs; i++)
    {
      int nv=gr[lastv][i];
      if(!used[nv])
      {
        used[nv]=1;
        qu.push(nv);
      }
    }
  }
  for(int i=0; i<n; i++) used[i]=0;
  used[lastv]=1;
  par[lastv]=lastv;
  root=lastv;
  qu.push(lastv);

  while(!qu.empty())
  {
    lastv=qu.front();
    qu.pop();
    int brs=gr[lastv].size();
    for(int i=0; i<brs; i++)
    {
      int nv=gr[lastv][i];
      if(!used[nv])
      {
        used[nv]=1;
        par[nv]=lastv;
        dpt[nv]=dpt[lastv]+1;
        qu.push(nv);
      }
    }
  }

  if(dpt[lastv]>=59)
  {
    for(int i=0; i<n; i++) tpos[i]=dpt[i]%60;
    for(int i=0; i<60; i++)
    {
      x|=(tval[p]<<tpos[p]);
      if(p==par[p]) break;
      tval[par[p]]=Move(par[p]);
      p=par[p];
    }
    destn[lastv]=-1;
    //cout<<'d'<<lastv<<endl;
    while(lastv!=par[lastv])
    {
      destn[par[lastv]]=lastv;
      //cout<<lastv<<endl;
      lastv=par[lastv];
    }
    for(int i=0; i<60; i++)
    {
      //cout<<x<<endl;
      x|=(tval[p]<<tpos[p]);
      if(destn[p]==-1) break;
      tval[destn[p]]=Move(destn[p]);
      p=destn[p];
    }
    return x;
  }
  /////cout<<dpt[lastv]<<endl;

  int lng=dpt[lastv]+1, nr=lastv;
  for(int i=1; i<lng/2; i++) nr=par[nr];
  for(int i=0; i<n; i++) used[i]=0;

  par[nr]=nr;
  euler_tour(nr);

  while(p!=par[p])
  {
      x|=(tval[p]<<tpos[p]);
      tval[par[p]]=Move(par[p]);
      p=par[p];
  }
  br=0;
  for(int i=0; i<n; i++) used[i]=0;
  euler_tour2(p);
  return x;
}

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) 
{
  n=N;
  m=M;
  p=P;
  tval[P]=V;
  for(int i=0; i<M; i++)
  {
    gr[A[i]].push_back(B[i]);
    gr[B[i]].push_back(A[i]);
  }
  return find_diam();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1296 KB Output is correct
2 Correct 1 ms 1308 KB Output is correct
3 Correct 1 ms 1308 KB Output is correct
4 Correct 1 ms 1312 KB Output is correct
5 Correct 1 ms 1300 KB Output is correct
6 Correct 1 ms 1312 KB Output is correct
7 Correct 1 ms 1316 KB Output is correct
8 Correct 2 ms 1312 KB Output is correct
9 Correct 1 ms 1312 KB Output is correct
10 Correct 1 ms 1300 KB Output is correct
11 Correct 2 ms 1640 KB Output is correct
12 Incorrect 1 ms 1300 KB Wrong Answer [7]
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 4456 KB Output is correct
2 Correct 18 ms 4652 KB Output is correct
3 Correct 17 ms 4640 KB Output is correct
4 Correct 12 ms 3128 KB Output is correct
5 Correct 10 ms 3128 KB Output is correct
6 Correct 9 ms 3128 KB Output is correct
7 Correct 10 ms 3132 KB Output is correct
8 Correct 10 ms 3132 KB Output is correct
9 Correct 10 ms 3132 KB Output is correct
10 Correct 9 ms 3396 KB Output is correct
11 Correct 9 ms 3276 KB Output is correct
12 Correct 9 ms 3000 KB Output is correct
13 Correct 10 ms 3060 KB Output is correct
14 Correct 10 ms 3124 KB Output is correct
15 Correct 10 ms 3132 KB Output is correct
16 Correct 10 ms 3140 KB Output is correct
17 Correct 10 ms 3136 KB Output is correct
18 Correct 10 ms 3128 KB Output is correct
19 Correct 10 ms 3348 KB Output is correct
20 Correct 7 ms 3128 KB Output is correct
21 Correct 7 ms 3136 KB Output is correct
22 Correct 12 ms 3124 KB Output is correct
23 Correct 10 ms 3128 KB Output is correct
24 Correct 9 ms 3092 KB Output is correct
25 Correct 9 ms 3124 KB Output is correct
26 Correct 10 ms 3128 KB Output is correct
27 Correct 9 ms 3132 KB Output is correct
28 Correct 10 ms 3128 KB Output is correct
29 Correct 7 ms 3100 KB Output is correct
30 Correct 9 ms 3124 KB Output is correct
31 Correct 1 ms 1312 KB Output is correct
32 Correct 0 ms 1312 KB Output is correct
33 Correct 0 ms 1316 KB Output is correct
34 Correct 1 ms 1312 KB Output is correct
35 Correct 1 ms 1324 KB Output is correct
36 Correct 0 ms 1300 KB Output is correct
37 Correct 0 ms 1300 KB Output is correct
38 Correct 1 ms 1296 KB Output is correct
39 Incorrect 1 ms 1312 KB Wrong Answer [7]
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1296 KB Output is correct
2 Correct 1 ms 1312 KB Output is correct
3 Correct 1 ms 1300 KB Output is correct
4 Correct 2 ms 1344 KB Output is correct
5 Correct 2 ms 1592 KB Output is correct
6 Correct 2 ms 1352 KB Output is correct
7 Correct 2 ms 1352 KB Output is correct
8 Correct 2 ms 1344 KB Output is correct
9 Correct 7 ms 3136 KB Output is correct
10 Correct 7 ms 3140 KB Output is correct
11 Correct 7 ms 3128 KB Output is correct
12 Correct 1 ms 1312 KB Output is correct
13 Correct 1 ms 1312 KB Output is correct
14 Correct 1 ms 1300 KB Output is correct
15 Correct 0 ms 1312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 4448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 4452 KB Output isn't correct
2 Halted 0 ms 0 KB -