답안 #1040657

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040657 2024-08-01T08:15:28 Z 비요뜨(#11041) The Ties That Guide Us (CEOI23_incursion) C++17
0 / 100
162 ms 11408 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=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;
  while (1) {
      vis[now]=true;
      if (now==r&&val==1) {
          return;
      }
      if (val==1) {
          int 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 (!vis[nt]) {
              nxt=nt;
              break;
          }
      }
      if (nxt==-1) {
          return;
      }
      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:52: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]
   52 |   for(int i=0;i<F.size();i++) {
      |               ~^~~~~~~~~
incursion.cpp:70:15: warning: unused variable 'val' [-Wunused-variable]
   70 |           int val=visit(p[now]);
      |               ^~~
incursion.cpp:75:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |       for(int i=0;i<adj[now].size();i++) {
      |                   ~^~~~~~~~~~~~~~~~
incursion.cpp:50:9: warning: unused variable 'fc' [-Wunused-variable]
   50 |     int fc=0;
      |         ^~
incursion.cpp:66:7: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |       if (now==r&&val==1) {
      |       ^~
incursion.cpp: In function 'std::vector<int> mark(std::vector<std::pair<int, int> >, int)':
incursion.cpp:32:6: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |   dfs(r,-1);
      |   ~~~^~~~~~
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);
      |                  ~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2820 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 162 ms 11408 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 65 ms 7600 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2820 KB Not correct
2 Halted 0 ms 0 KB -