제출 #1309393

#제출 시각아이디문제언어결과실행 시간메모리
1309393marcogambaroTelepathy (JOI25_telepathy)C++20
0 / 100
4 ms816 KiB
#include "telepathy.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> G; vector<int> P; int d1, d2; void read(int N, vector<int> &a, vector<int> &b) { for(int i=0; i<N-1; i++) { G[a[i]].push_back(b[i]); G[b[i]].push_back(a[i]); } } void findd(int N) { int M = 0; vector<int> d(N); vector<int> from(N); auto dfs = [&](int n, int f, auto &&dfs) -> void { if(n == -1) return; from[n] = f; for(int n2: G[n]) { if(n2 == f) continue; d[n2] = d[n]+1; if(d[n2] >= d[M]) M = n2; dfs(n2, n, dfs); } }; dfs(0, -1, dfs); d[M] = 0; dfs(M, -1, dfs); d1 = M; for(int i=0; i<d[M]/2; i++) { d1 = from[d1]; } if(d[M]%2) d2 = from[d1]; P.resize(N); auto dfs2 = [&](int n, int f, auto &&dfs2) -> void { if(n == -1) return; for(int n2: G[n]) { if(n2 == f) continue; P[n2] = n; dfs2(n2, n, dfs2); } }; dfs2(d1, d2, dfs2); dfs2(d2, d1, dfs2); P[d1] = d1; if(d2 != -1) P[d2] = d2; } std::vector<int> Aitana(int N, std::vector<int> A, std::vector<int> B, int S, int subtask) { G = vector(N, vector<int>()); read(N, A, B); findd(N); vector<int> opp = {3, -2, 0, 11, 37, -23, 0, 20}; stack<int> st; vector<int> ans = {S}; int n = S; for(int i=0; i<opp.size() && n != d1 && n != d2; i++) { int x = opp[i]; if(x > 0) { for(int j=0; j<x; j++) { ans.push_back(P[n]); st.push(n); n = P[n]; } } else if(x < 0) { for(int j=0; j<-x; j++) { ans.push_back(st.top()); n = st.top(); st.pop(); } } else { i++; x = opp[i]; for(int j=0; j<x; j++) ans.push_back(n); } } while(n != d1 && n != d2) { ans.push_back(P[n]); n = P[n]; } while(ans.size() <= 10*N) { ans.push_back(n); } return ans; return vector<int>(10*N+1, S); } std::vector<int> Bruno(int N, std::vector<int> C, std::vector<int> D, int T, int subtask) { G = vector(N, vector<int>()); read(N, C, D); findd(N); vector<int> opp = {0, 2, 13, -8, 0, 29, 43}; stack<int> st; vector<int> ans = {T}; int n = T; for(int i=0; i<opp.size() && n != d1 && n != d2; i++) { int x = opp[i]; if(x > 0) { for(int j=0; j<x; j++) { ans.push_back(P[n]); st.push(n); n = P[n]; } } else if(x < 0) { for(int j=0; j<-x; j++) { ans.push_back(st.top()); n = st.top(); st.pop(); } } else { i++; x = opp[i]; for(int j=0; j<x; j++) ans.push_back(n); } } while(n != d1 && n != d2) { ans.push_back(P[n]); n = P[n]; } while(ans.size() <= 10*N) { if(d2 == -1 || n == d2) { ans.push_back(d1); n = d1; } else { ans.push_back(d2); n = d2; } } return ans; return vector<int>(10*N+1, T); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...