답안 #1072111

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072111 2024-08-23T14:25:04 Z edogawa_something The Ties That Guide Us (CEOI23_incursion) C++17
0 / 100
2000 ms 39652 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 adj[M];
bool vis[M];
ll 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);
}
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++)
    adj[F[i].F].pb(F[i].S),adj[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(adj[i].size()==1)
      st=i;
  }
  mdfs(st);
  if((dis[curr]>n/2)^(t==0)) {
    for(int i=1;i<=n;i++)
      dis[i]=n-1-dis[i];
  }
  if(t==1) {
    ll par=curr;
    ll cnt=0;
    while(t==1) {
      for(auto it:adj[curr]) {
        if(dis[it]>dis[curr]) {
          par=curr,curr=it;
          t=visit(int(it));
          break;
        }
      }
    }
    visit(int(par));
    return;
  }
  else {
    while(t==0) {
      for(auto it:adj[curr]) {
        if(dis[it]<dis[curr]) {
          curr=it;
          t=visit(int(it));
          break;
        }
      }
    }
    return;
  }
}

Compilation message

incursion.cpp: In function 'std::vector<int> mark(std::vector<std::pair<int, int> >, int)':
incursion.cpp:25: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]
   25 |   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++)
      |               ~^~~~~~~~~
incursion.cpp:72:8: warning: unused variable 'cnt' [-Wunused-variable]
   72 |     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);
      |                  ~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 26376 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3048 ms 39652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3135 ms 36508 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 26376 KB Correct
2 Execution timed out 3048 ms 39652 KB Time limit exceeded
3 Halted 0 ms 0 KB -