제출 #1295883

#제출 시각아이디문제언어결과실행 시간메모리
1295883SugarCubes69세계 지도 (IOI25_worldmap)C++20
15 / 100
14 ms3268 KiB
//orz Dominator069 #include "worldmap.h" #include <bits/stdc++.h> using namespace std; typedef int ll; const ll maxn = 45; vector<ll> adj[maxn]; bool visited[maxn]; ll par[maxn],dep[maxn],tin[maxn],tout[maxn],dfscnt; void dfs(ll x){ tin[x] = dfscnt++; visited[x] = true; for(ll child:adj[x]) if(!visited[child]){ par[child] = x; dep[child] = dep[x]+1; dfs(child); } tout[x] = dfscnt; } ll bad[maxn]; vector<ll> ord; void dfs2(ll x){ visited[x] = true; ord.push_back(x); for(ll child:adj[x]) if(!visited[child] && !bad[child]){ dfs2(child); ord.push_back(x); } for(ll child:adj[x]) if(!visited[child] && bad[child]){ dfs2(child); ord.push_back(x); } } vector < vector<int> > create_map ( int N, int M, vector <int> a, vector <int> b ) { for(int i=1;i<=N;i++) adj[i].clear(); for(int i=0;i<M;i++){ adj[a[i]].push_back(b[i]); adj[b[i]].push_back(a[i]); } fill(visited,visited+N+1,false); dfscnt = 0; par[1] = -1; dep[1] = 0; dfs(1); fill(bad,bad+N+1,false); ll pos = max_element(dep+1,dep+N+1)-dep; for(;pos!=1;pos=par[pos]) bad[pos] = true; ord.clear(); fill(visited,visited+N+1,false); dfs2(1); vector<vector<int>> ans = vector<vector<int>>(ord.size(),vector<int>(ord.size())); for(int i=0;i<ord.size();i++){ for(int j=0;j<ord.size();j++) ans[i][j] = ord[i]; } return ans; } /*int main() { int T; assert(1 == scanf("%d", &T)); std::vector<int> Nt(T), Mt(T); std::vector<std::pair<std::vector<int>, std::vector<int>>> AB; for (int t = 0; t < T; ++t) { assert(2 == scanf("%d %d", &Nt[t], &Mt[t])); int M = Mt[t]; std::vector<int> A(M), B(M); for (int i = 0; i < Mt[t]; i++) { assert(2 == scanf("%d %d", &A[i], &B[i])); } AB.push_back(make_pair(A, B)); } fclose(stdin); std::vector<std::vector<std::vector<int>>> Ct; for (int t = 0; t < T; t++) { int N = Nt[t], M = Mt[t]; std::vector<int> A = AB[t].first, B = AB[t].second; auto C = create_map(N, M, A, B); Ct.push_back(C); } for (int t = 0; t < T; t++) { auto& C = Ct[t]; int P = (int)C.size(); std::vector<int> Q(P); for (int i = 0; i < P; ++i) Q[i] = (int)C[i].size(); printf("%d\n", P); for (int i = 0; i < P; ++i) printf("%d%c", Q[i], " \n"[i + 1 == P]); printf("\n"); for (int i = 0; i < P; i++) { for (int j = 0; j < Q[i]; j++) { printf("%d%c", C[i][j], " \n"[j + 1 == Q[i]]); } } if (t < T - 1) printf("\n"); } fclose(stdout); return 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...