forked from Yawn-Sean/Daily_CF_Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20240604 cc4414's submission for CF1133F2 (Yawn-Sean#3183)
* 20240227 cc4414's submission * Create cf1260c_cc4414.java 20240228 cc4414's submission for CF1260C * 20240228 cc4414's submission for CF1152D * 20240229 cc4414's submission for 1512G * 20240229 cc4414's submission for CF258C * 20240301 cc4414's submission for 687A * 20240301 cc4414's submission for 1498E * 20240302 cc4414's submission for CF1936C * Create cf749d_cc4414.java 20240424 cc4414's submission for CF749D * 20240508 cc4414's submission for CF721D * 20240511 cc4414's submission for CF852F * 20240513 cc4414's submission for CF799C * 20240513 cc4414's submission for CF1029D * 20240514 cc4414's submission for CF965D * 20240514 cc4414's submission for CF914C * 20240518 cc4414's submission for CF1056D * 20240524 cc4414's submission for CF301B * 20240604 cc4414's submission for CF1133F2 * 20240604 cc4414's submission for CF1949I
- Loading branch information
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
daily_problems/2024/06/0604/personal_submission/cf1133f2_cc4414.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Submission link: https://codeforces.com/contest/1133/submission/264089918 | ||
class Solution { | ||
public List<int[]> solve(int[][] edges, int n, int d) { | ||
List<int[]> list = new ArrayList<>(); | ||
Set<Integer>[] sets = new Set[n]; | ||
for (int i = 0; i < n; i++) { | ||
sets[i] = new HashSet<>(); | ||
} | ||
for (int[] edge : edges) { | ||
sets[edge[0]].add(edge[1]); | ||
sets[edge[1]].add(edge[0]); | ||
} | ||
if (sets[0].size() < d) { | ||
return null; | ||
} | ||
UnionFind unionFind = new UnionFind(n); | ||
for (int[] edge : edges) { | ||
if (edge[0] != 0 && edge[1] != 0) { | ||
unionFind.union(edge[0], edge[1]); | ||
} | ||
} | ||
int t = unionFind.size - 1; | ||
if (d < t) { | ||
return null; | ||
} | ||
t = d; | ||
boolean[] vis = new boolean[n]; | ||
vis[0] = true; | ||
ArrayDeque<Integer> deque = new ArrayDeque<>(); | ||
for (Integer v : sets[0]) { | ||
if (unionFind.isUnion(0, v)) { | ||
continue; | ||
} | ||
unionFind.union(0, v); | ||
list.add(new int[]{0, v}); | ||
deque.add(v); | ||
vis[v] = true; | ||
t--; | ||
} | ||
for (Integer v : sets[0]) { | ||
if (t == 0) { | ||
break; | ||
} | ||
if (vis[v]) { | ||
continue; | ||
} | ||
list.add(new int[]{0, v}); | ||
deque.add(v); | ||
vis[v] = true; | ||
t--; | ||
} | ||
while (!deque.isEmpty()) { | ||
Integer remove = deque.remove(); | ||
for (Integer w : sets[remove]) { | ||
if (vis[w]) { | ||
continue; | ||
} | ||
list.add(new int[]{remove, w}); | ||
deque.add(w); | ||
vis[w] = true; | ||
} | ||
} | ||
return list; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
daily_problems/2024/06/0604/personal_submission/cf1949i_cc4414.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Submission link: https://codeforces.com/contest/1949/submission/264101759 | ||
class Solution { | ||
public boolean solve(long[][] a) { | ||
double eps = 1e-9; | ||
int n = a.length; | ||
boolean[][] con = new boolean[n][n]; | ||
for (int i = 0; i < n; i++) { | ||
for (int j = i + 1; j < n; j++) { | ||
long dx = a[i][0] - a[j][0]; | ||
long dy = a[i][1] - a[j][1]; | ||
if (Math.sqrt(dx * dx + dy * dy) - a[i][2] - a[j][2] < eps) { | ||
con[i][j] = true; | ||
con[j][i] = true; | ||
} | ||
} | ||
} | ||
boolean[] vis = new boolean[n]; | ||
int[] color = new int[n]; | ||
for (int i = 0; i < n; i++) { | ||
if (vis[i]) { | ||
continue; | ||
} | ||
int[] cnt = new int[2]; | ||
cnt[0] = 1; | ||
boolean b = true; | ||
ArrayDeque<Integer> deque = new ArrayDeque<>(); | ||
deque.add(i); | ||
vis[i] = true; | ||
while (!deque.isEmpty()) { | ||
Integer remove = deque.remove(); | ||
for (int j = 0; j < n; j++) { | ||
if (con[remove][j]) { | ||
if (vis[j]) { | ||
if (color[remove] == color[j]) { | ||
b = false; | ||
} | ||
continue; | ||
} | ||
deque.add(j); | ||
vis[j] = true; | ||
color[j] = color[remove] ^ 1; | ||
cnt[color[j]]++; | ||
} | ||
} | ||
} | ||
if (b && cnt[0] != cnt[1]) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |