답안 #1040671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040671 2024-08-01T08:23:44 Z 비요뜨(#11041) The Ties That Guide Us (CEOI23_incursion) C++17
컴파일 오류
0 ms 0 KB
#include <vector>
//#include "incursion.h"
#include <bits/stdc++.h>
using namespace std;

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

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

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;
  while (now!=-1) {
      v[now-1]=0;
      now=p[now];
  }
  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();
    }
  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;
      if (now==r&&val==1) {
          return;
      }
      if (val==1) {
          val=visit(p[now]);
          now=p[now];
          continue;
      }
      int nxt=-1;
      for(int i=0;i<adj[now].size();i++) {
          int nt=adj[now][i];
          if (nt!=p[now]&&!vis[nt]) {
              nxt=nt;
              break;
          }
      }
      if (nxt==-1) {
          return;
      }
      val=visit(nxt);
      now=nxt;
  }
  return;
}

Compilation message

incursion.cpp: In function 'void dfs(int, int)':
incursion.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     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:23: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]
   23 |   for(int i=0;i<F.size();i++) {
      |               ~^~~~~~~~~
incursion.cpp: In function 'void locate(std::vector<std::pair<int, int> >, int, int)':
incursion.cpp:55: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]
   55 |   for(int i=0;i<F.size();i++) {
      |               ~^~~~~~~~~
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/vector:60,
                 from incursion.cpp:1:
/usr/include/c++/10/type_traits: In substitution of 'template<class _Fn, class ... _Args> using invoke_result_t = typename std::invoke_result::type [with _Fn = int&; _Args = {}]':
/usr/include/c++/10/variant:1705:13:   required from 'constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...) [with _Visitor = int&; _Variants = {}]'
incursion.cpp:74:27:   required from here
/usr/include/c++/10/type_traits:2957:11: error: no type named 'type' in 'struct std::invoke_result<int&>'
 2957 |     using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
      |           ^~~~~~~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from incursion.cpp:3:
/usr/include/c++/10/variant: In instantiation of 'constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...) [with _Visitor = int&; _Variants = {}]':
incursion.cpp:74:27:   required from here
/usr/include/c++/10/variant:1708:13: error: no type named 'type' in 'struct std::invoke_result<int&>'
 1708 |       using _Tag = __detail::__variant::__deduce_visit_result<_Result_type>;
      |             ^~~~
incursion.cpp:79:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |       for(int i=0;i<adj[now].size();i++) {
      |                   ~^~~~~~~~~~~~~~~~
incursion.cpp:50:9: warning: unused variable 'fc' [-Wunused-variable]
   50 |     int fc=0;
      |         ^~
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);
      |                  ~~~~~~~~~~~~~~~^~~~