Submission #980738

#TimeUsernameProblemLanguageResultExecution timeMemory
980738TheEpicCowOfLifeIsland Hopping (JOI24_island)C++17
29 / 100
6 ms1368 KiB
#include <bits/stdc++.h> #include "island.h" using namespace std; vector<int> g[305]; int d[305][305]; int ua[305]; vector<int> ug[305]; void dfs(int x, int par, int root, int depth){ d[root][x] = depth; d[x][root] = depth; for (int tgt : g[x]){ if (tgt == par) continue; dfs(tgt,x,root,depth+1); } } int f(int x){ if (ua[x] == x) return x; return ua[x] = f(ua[x]); } void merge(int x, int y){ int fx = f(x); int fy = f(y); if (f(x) == f(y)){ return; } if (ug[fx].size() > ug[fy].size()){ swap(fx,fy); swap(x,y); } g[x].push_back(y); g[y].push_back(x); answer(x,y); for (int tgt : ug[fx]){ ug[fy].push_back(tgt); dfs(tgt,-1,tgt,0); } ua[fx] = fy; ug[fx].clear(); } // "All neighbours known" bool ann[305]; int gi[305]; void solve(int N, int L) { for (int i = 1; i <= N; i++){ ug[i].push_back(i); ua[i] = i; gi[i] = 1; } for (int i = N; i > 1; i--){ int ret = query(i,1); merge(i,ret); } ann[1] = true; for (int cur_ann = 1; cur_ann < N; cur_ann++){ for (int i = 1; i <= cur_ann; i++){ for (int j: g[i]){ if (ann[j]) continue; bool can_expand = true; for (int tgt: g[j]){ if (!ann[tgt]) { can_expand = false; break; } } if (can_expand){ int ret = query(j,++gi[j]); if (d[ret][j] == 2){ ann[j] = true; } else{ merge(ret,j); } } } } ann[cur_ann+1] = true; } // int variable_example = query(1, 1); // for (int i = 2; i <= N; i++) { // answer(1, i); // } }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...