Submission #1040716

# Submission time Handle Problem Language Result Execution time Memory
1040716 2024-08-01T08:42:38 Z 비요뜨(#11041) The Ties That Guide Us (CEOI23_incursion) C++17
0 / 100
130 ms 14416 KB
#include <vector>
#include "incursion.h"
#include <bits/stdc++.h>
using namespace std;

int p[45001];
bool vis[45001];
vector<int> adj[45001];
int sz[45001];

void dfs(int v,int pr) {
    p[v]=pr;
    sz[v]=1;
    for(int i=0;i<adj[v].size();i++) {
        int nt=adj[v][i];
        if (nt!=pr) {
            dfs(nt,v);
            sz[v]+=sz[nt];
        }
    }
}

std::vector<int> mark(std::vector<std::pair<int, int>> F, int safe) {
  int n=F.size()+1;
  int r;
  for(int i=0;i<F.size();i++) {
      adj[F[i].first].push_back(F[i].second);
      adj[F[i].second].push_back(F[i].first);
  }
  for(int i=1;i<=n;i++) {
      if (adj[i].size()==2) {
          r=i;
      }
  }
  dfs(r,-1);
  vector<int> v(n);
  for(int i=0;i<n;i++) {
      v[i]=1;
  }
  int now=safe;
  v[safe-1]=0;
  int pr=-1;
  while (now!=r) {
      pr=now;
      now=p[now];
      int ot;
      for(int i=0;i<adj[now].size();i++) {
          if (adj[now][i]!=p[now]&&adj[now][i]!=pr) {
              ot=pr;
              break;
          }
      }
      if (sz[ot]>sz[pr]) {
          v[now-1]=1;
      }
      else {
          v[now-1]=0;
      }
  }
  if (safe==r) {
      v[safe-1]=1;
  }
  return v;
}

void locate(std::vector<std::pair<int, int>> F, int curr, int t) {
    int n=F.size()+1;
    int fc=0;
    int r;
    for(int i=1;i<=n;i++) {
        adj[i].clear();
        sz[i]=0;
    }
  for(int i=0;i<F.size();i++) {
      adj[F[i].first].push_back(F[i].second);
      adj[F[i].second].push_back(F[i].first);
  }
  for(int i=1;i<=n;i++) {
      if (adj[i].size()==2) {
          r=i;
      }
  }
  dfs(r,-1);
  int now=curr;
  int val=t;
  memset(vis,0,sizeof(vis));
  while (1) {
      vis[now]=true;
      bool flag=false;
      if (now==r&&val==1) {
          flag=true;
      }
      //printf("%d %d\n",now,val);
      if (val==1) {
          //printf(".\n");
          val=visit(p[now]);
          now=p[now];
          continue;
      }
      int nxt=-1;
      int ot=-1;
      for(int i=0;i<adj[now].size();i++) {
          int nt=adj[now][i];
          if (nt!=p[now]&&!vis[nt]) {
              if (nxt==-1) {
                  nxt=nt;
              }
              else {
                  ot=nt;
              }
          }
      }
      if (nxt==-1) {
          return;
      }
      //printf(".%d %d\n",nxt,ot);
      if (flag) {
          if (ot==-1||sz[nxt]<sz[ot]) {
              val=visit(nxt);
              now=nxt;
          }
          else {
              val=visit(ot);
              now=ot;
          }
          continue;
      }
      if (ot==-1||sz[nxt]>sz[ot]) {
          val=visit(nxt);
          now=nxt;
      }
      else {
          val=visit(ot);
          now=ot;
      }
  }
  return;
}

Compilation message

incursion.cpp: In function 'void dfs(int, int)':
incursion.cpp:14:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i=0;i<adj[v].size();i++) {
      |                 ~^~~~~~~~~~~~~~
incursion.cpp: In function 'std::vector<int> mark(std::vector<std::pair<int, int> >, int)':
incursion.cpp:26:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   for(int i=0;i<F.size();i++) {
      |               ~^~~~~~~~~
incursion.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |       for(int i=0;i<adj[now].size();i++) {
      |                   ~^~~~~~~~~~~~~~~~
incursion.cpp: In function 'void locate(std::vector<std::pair<int, int> >, int, int)':
incursion.cpp:74:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for(int i=0;i<F.size();i++) {
      |               ~^~~~~~~~~
incursion.cpp:102:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |       for(int i=0;i<adj[now].size();i++) {
      |                   ~^~~~~~~~~~~~~~~~
incursion.cpp:68:9: warning: unused variable 'fc' [-Wunused-variable]
   68 |     int fc=0;
      |         ^~
incursion.cpp:83:6: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   83 |   dfs(r,-1);
      |   ~~~^~~~~~
incursion.cpp: In function 'std::vector<int> mark(std::vector<std::pair<int, int> >, int)':
incursion.cpp:35:6: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |   dfs(r,-1);
      |   ~~~^~~~~~
incursion.cpp:53:16: warning: 'ot' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |       if (sz[ot]>sz[pr]) {
      |           ~~~~~^
interface.cpp: In function 'int main()':
interface.cpp:44:55: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |     if(fread(T.data(), sizeof(int), 2 * N - 2, stdin) != 2 * N - 2) exit(0);
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
interface.cpp:50:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         int l = (numbers.size() == N ? N : 0);
      |                  ~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2816 KB Correct
# Verdict Execution time Memory Grader output
1 Runtime error 43 ms 14416 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 8024 KB Correct
2 Correct 70 ms 8056 KB Correct
3 Correct 70 ms 7952 KB Correct
4 Correct 73 ms 11420 KB Correct
5 Correct 95 ms 11648 KB Correct
6 Correct 130 ms 11456 KB Correct
7 Correct 63 ms 7836 KB Correct
8 Correct 74 ms 7848 KB Correct
9 Correct 78 ms 7720 KB Correct
10 Correct 68 ms 7776 KB Correct
11 Correct 73 ms 7640 KB Correct
12 Correct 72 ms 7812 KB Correct
13 Correct 70 ms 7772 KB Correct
14 Correct 49 ms 6704 KB Correct
15 Correct 44 ms 6712 KB Correct
16 Correct 74 ms 7788 KB Correct
17 Correct 60 ms 7836 KB Correct
18 Correct 64 ms 7812 KB Correct
19 Correct 63 ms 7756 KB Correct
20 Correct 49 ms 6712 KB Correct
21 Correct 49 ms 6688 KB Correct
22 Correct 44 ms 6592 KB Correct
23 Correct 50 ms 6564 KB Correct
24 Correct 55 ms 6572 KB Correct
25 Correct 39 ms 6556 KB Correct
26 Correct 64 ms 7812 KB Correct
27 Correct 75 ms 7796 KB Correct
28 Correct 63 ms 8040 KB Correct
29 Correct 70 ms 7800 KB Correct
30 Correct 75 ms 7836 KB Correct
31 Correct 65 ms 7928 KB Correct
32 Correct 57 ms 7836 KB Correct
33 Correct 69 ms 7812 KB Correct
34 Correct 88 ms 8024 KB Correct
35 Correct 67 ms 7836 KB Correct
36 Correct 79 ms 8092 KB Correct
37 Correct 66 ms 7792 KB Correct
38 Correct 71 ms 7812 KB Correct
39 Correct 75 ms 7968 KB Correct
40 Correct 66 ms 7800 KB Correct
41 Correct 74 ms 7768 KB Correct
42 Correct 77 ms 7808 KB Correct
43 Correct 69 ms 7888 KB Correct
44 Correct 71 ms 7816 KB Correct
45 Correct 68 ms 7812 KB Correct
46 Correct 79 ms 8016 KB Correct
47 Correct 75 ms 7940 KB Correct
48 Correct 71 ms 7800 KB Correct
49 Correct 63 ms 7816 KB Correct
50 Correct 73 ms 8056 KB Correct
51 Correct 75 ms 7796 KB Correct
52 Correct 81 ms 7788 KB Correct
53 Correct 62 ms 7804 KB Correct
54 Correct 61 ms 7816 KB Correct
55 Correct 71 ms 7792 KB Correct
56 Correct 73 ms 8180 KB Correct
57 Correct 82 ms 8036 KB Correct
58 Correct 60 ms 8048 KB Correct
59 Incorrect 78 ms 8072 KB Not correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2816 KB Correct
2 Runtime error 43 ms 14416 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -