Submission #1072089

# Submission time Handle Problem Language Result Execution time Memory
1072089 2024-08-23T14:11:15 Z edogawa_something The Ties That Guide Us (CEOI23_incursion) C++17
Compilation error
0 ms 0 KB
#include "incursion.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
const ll M=5e5+10;
const ll inf=2e18;
vii adjj[M],adj[M];
bool vis[M],viss[M];
ll diss[M],dis[M];
void mdfs(ll x,ll d=0) {
  if(vis[x])
    return;
  vis[x]=1;
  dis[x]=d;
  for(auto it:adj[x])
    mdfs(it,d+1);
}
void ldfs(ll x,ll d=0) {
  if(viss[x])
    return;
  viss[x]=1;
  diss[x]=d;
  for(auto it:adjj[x])
    ldfs(it,d+1);
}
std::vector<int> mark(std::vector<std::pair<int, int>> F, int safe) {
  for(int i=0;i<F.size();i++)
    adj[F[i].F].pb(F[i].S),adj[F[i].S].pb(F[i].F);
  ll n=F.size()+1;
  ll st=0;
  for(int i=1;i<=n;i++) {
    if(adj[i].size()==1)
      st=i;
  }
  vector<int>ans;
  mdfs(st);
  if(dis[safe]>n/2) {
    for(int i=1;i<=n;i++) {
      if(dis[i]>=dis[safe])
        ans.pb(1);
      else
        ans.pb(0);
    }
  }
  else {
    for(int i=1;i<=n;i++) {
      if(dis[i]<=dis[safe])
        ans.pb(1);
      else
        ans.pb(0);
    }
  }
  return ans;
}

void locate(std::vector<std::pair<int, int>> F, int curr, int t) {
  for(int i=0;i<F.size();i++)
    adjj[F[i].F].pb(F[i].S),adjj[F[i].S].pb(F[i].F);
  ll n=F.size()+1;
  for(int i=1;i<=n;i++)
    vis[i]=0;
  ll st=0;
  for(int i=1;i<=n;i++) {
    if(adjj[i].size()==1)
      st=i;
  }
  ldfs(st);
  if((diss[curr]>n/2)^(t==0)) {
    for(int i=1;i<=n;i++)
      diss[i]=n-1-diss[i];
  }
  if(t==1) {
    ll par=curr;
    ll cnt=0;
    while(t==1) {
      for(auto it:adjj[curr]) {
        if(diss[it]>diss[curr]) {
        par=curr,curr=it;
          t=visit(it);
          break;
        }
      }
    }
    visit(par);
    return;
  }
  else {
    while(t==0) {
      for(auto it:adjj[curr]) {
        if(diss[it]<diss[curr]) {
          curr=it;
          t=visit(it);
          break;
        }
      }
    }
    return;
  }
}

Compilation message

incursion.cpp: In function 'std::vector<int> mark(std::vector<std::pair<int, int> >, int)':
incursion.cpp:33: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]
   33 |   for(int i=0;i<F.size();i++)
      |               ~^~~~~~~~~
incursion.cpp: In function 'void locate(std::vector<std::pair<int, int> >, int, int)':
incursion.cpp:63: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]
   63 |   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.h:1,
                 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 = long long int&; _Args = {}]':
/usr/include/c++/10/variant:1705:13:   required from 'constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...) [with _Visitor = long long int&; _Variants = {}]'
incursion.cpp:85:21:   required from here
/usr/include/c++/10/type_traits:2957:11: error: no type named 'type' in 'struct std::invoke_result<long long 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:2:
/usr/include/c++/10/variant: In instantiation of 'constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...) [with _Visitor = long long int&; _Variants = {}]':
incursion.cpp:85:21:   required from here
/usr/include/c++/10/variant:1708:13: error: no type named 'type' in 'struct std::invoke_result<long long int&>'
 1708 |       using _Tag = __detail::__variant::__deduce_visit_result<_Result_type>;
      |             ^~~~
incursion.cpp:80:8: warning: unused variable 'cnt' [-Wunused-variable]
   80 |     ll cnt=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);
      |                  ~~~~~~~~~~~~~~~^~~~