Submission #1081443

#TimeUsernameProblemLanguageResultExecution timeMemory
1081443LCJLYThe Ties That Guide Us (CEOI23_incursion)C++17
12 / 100
267 ms15496 KiB
#include "incursion.h" #include <bits/stdc++.h> //#include "sample_grader.cpp" using namespace std; //#define int long long //#define ld long double #define show(x,y) cout << y << " " << #x << endl; #define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl; #define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl; #define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl; typedef pair<int,int>pii; typedef pair<pii,int>pi2; int n; vector<int>adj[45005]; int sz[45005]; int pp[45005]; int child[45005]; void dfs(int index, int par){ sz[index]=1; for(auto it:adj[index]){ if(it==par) continue; dfs(it,index); pp[it]=index; child[index]=it; sz[index]+=sz[it]; } } vector<int>mark(vector<pair<int, int>> F, int safe){ n=F.size()+1; for(int x=0;x<n-1;x++){ adj[F[x].first].push_back(F[x].second); adj[F[x].second].push_back(F[x].first); } dfs(safe,-1); vector<int>ans(n); for(int x=1;x<=n;x++){ if(x==safe){ ans[x-1]=2; } else if(sz[x]-1<n-sz[x]){ ans[x-1]=0; } else ans[x-1]=1; } return ans; } //visit() void locate(vector<pair<int, int>> F, int curr, int t){ n=F.size()+1; for(int x=0;x<=n;x++){ adj[x].clear(); sz[x]=0; } for(int x=0;x<n-1;x++){ adj[F[x].first].push_back(F[x].second); adj[F[x].second].push_back(F[x].first); } for(int x=1;x<=n;x++){ if(adj[x].size()==1){ dfs(x,-1); break; } } int cur=curr; //potentially start at centroid int take=-1; for(int i=0;i<2;i++){ if(t==2){ return; } else if(t==1){ //go to smaller side if(sz[cur]-1>=n-sz[cur]){ t=visit(pp[cur]); take=cur; cur=pp[cur]; } else{ t=visit(child[cur]); take=cur; cur=child[cur]; } } else{ if(sz[cur]-1<n-sz[cur]){ t=visit(pp[cur]); take=cur; cur=pp[cur]; } else{ t=visit(child[cur]); take=cur; cur=child[cur]; } } } while(t!=2){ if(t==0){ //go to larger one if(pp[cur]!=take&&sz[cur]-1<n-sz[cur]){ t=visit(pp[cur]); take=cur; cur=pp[cur]; } else{ t=visit(child[cur]); take=cur; cur=child[cur]; } } else if(t==1){ //go to smaller one if(pp[cur]!=take&&sz[cur]-1>=n-sz[cur]){ t=visit(pp[cur]); take=cur; cur=pp[cur]; } else{ t=visit(child[cur]); take=cur; cur=child[cur]; } } } }

Compilation message (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...