We will hold KAJIMA CORPORATION CONTEST 2025 (AtCoder Beginner Contest 394).
- Contest URL: https://atcoder.jp/contests/abc394
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20250222T2100&p1=248
- Duration: 100 minutes
- Writer: math957963, cn449
- Tester: sotanishy, toam
- Rated range: ~ 1999
- The point values: 100-200-300-400-450-500-600
We are looking forward to your participation!








If this ABC as shit as the last ABC, I will ban you.
lol
Although you are not the true system user, I still upvote your comment.
As shit as before
it seems blogs of ABC get less and less upvotes even get downvotes.
upd: this round is worse than last one again.
Wish no more AI Best Contest plz.
painful
Why ABC G. is so hard?
Its not.
Problem E is very similar to [POI 2009] Bytie-boy's Walk.
In POI, it shows us that E can be solved with time complexity $$$O(n^2V+nm)$$$. ($$$V=26$$$, $$$m$$$ is the number of edges).
Why this gives TLE for E in 2 test cases ?
How to solve E?
man how i do the c better than this ? Sorry my english is bad :(
iterate from right to left if WA is found replace it with AC
Anyone could please provide a testcase for my submissión for problem D? I failed just two cases :')
My submission
Thanks in advance
It's just a simple stack problem!
Maybe you need a better solution.
after contest i tried with o3-mini it solves E in one shot after giving my intuition. my TLE code : https://atcoder.jp/contests/abc394/submissions/63054891 o3-mini code: https://atcoder.jp/contests/abc394/submissions/63064525
today's problem set was nice but D was way more easier than C for me
I'm surprised to see the o3-mini code passing the time limit. The complexity is $$$O(n^4)$$$ and it takes 8s on a max test.
Why is this wrong for F Alkane?
... ~~~~~
ll bfs(int start, vector<vector> &adj, vector &visited) { queue q; q.push(start); visited[start] = true; ll component_size = 0;
while (!q.empty()) { ll node = q.front(); q.pop(); component_size++; for (auto neighbor : adj[node]) { if (!visited[neighbor]) { visited[neighbor] = true; q.push(neighbor); } } } return component_size;}
void solve() { ll n; cin >> n; vector<vector> adj(n + 1);
for (int i = 0; i < n - 1; i++) { ll u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } vector<ll> degree(n + 1); for (int i = 1; i <= n; i++) { degree[i] = adj[i].size(); } vector<ll> four, leaf; for (int i = 1; i <= n; i++) { if (degree[i] == 1) { leaf.push_back(i); } else if (degree[i] == 4) { four.push_back(i); } else { adj[i].clear(); } } vector<bool> visited(n + 1, false); ll ans = 0; for (int i = 0; i <= four.size(); i++) { if (!visited[i]) { ll sizeofcomp = bfs(i, adj, visited); ans = max(ans, sizeofcomp); } } if(four.size()==0) { cout << -1 << endl; return; } cout << ans << endl;}
int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll t=1; while (t--) { solve(); } return 0;} ~~~~~
I had the same idea and i can't figure out what's wrong either...
This is wrong because you can take the nodes which have degree > 4 in the original graph to be the part of the subgraph. You just need to ensure that in the subgraph the degree is exactly 4.
E.g. case:
Here in the original graph, the degree of node 1 is 5, your solution will ignore the node 1. But you can take nodes 1, 2, 3, 4, 5 and create an alkane out of them.
OH Yes you are right , i mistakenly thought that given inputs are having degree of any node at max 4
The problems in ABC contests are becoming increasingly easier, making rankings largely dependent on the speed of coding.
e.g. slower 10 min will get nearly 1000 rank down
For Problem F: My code is working on 1-39 testcases, and WA on 40-59, please find error...
Problems suddenly got considerably hard starting from E. I breezed through A~D in 20 minutes, and spent 60 minutes to solve E.
How to solve G? I figured that the optimal route will pass through a floor f such that when considering only buildings with heights >=
f, the source and destination would belong to same connected component.To find this value of
ffor each query, I thought I could do a binary search but then maintaining the UnionFind structure would takeO(N)per query, which is too slow. Another approach I thought of was to solve offline by adding each building one-by-one in decreasing order but then needing to check allQqueries after each addition is again too slow.consider small to large
You can construct a minimum spanning tree and then use binary lifting to find the minimal edge weight on the path between nodes.
I suppose the edge weights when constructing MST are simply the heights of building in each cell? Then I have a follow-up question:
Let's say that there are two nodes A and B and minimum wt edge on the path A->B in MST is X. How do I know that there is not another path (not covered by the MST) that contains Y (>X) and also connect A and B? It's possible that going from source to dest using this Y edge would be cheaper, isn't it?
You are correct about the edge weight being the building height. As for the second part, I incorrectly wrote minimum spanning tree when it should have been maximum spanning tree. Sorry for the confusion
G is not good. Extremely straightforward idea, but pain in the ass to implement, not what I expect from atcoder contests. Rest of the problems were alright tbh.
Great contest. Could not solve E and F. Didn't even tried G but had fun. Problems are good. Thank you AtCoder team.
Leaving Editorial of F for anyone like me out there cause it took me a 1 and a half days to solve it completely and most of the time on what resources to refer.
re-routing,in-out dpanddp on trees.3a. If this node is from where my answer starts, then what is the maximum I can make?
3b. But it should also have degree 4 to be valid how can I check that.
3c. Either the current node can have a degree 4 or I am a single node which is the end to an alkane which has degree 4 somewhere nested
3d. How to keep track of the 4 degree nodes? Not required because if the nodes are >= 4 then the degree has to be minimum 4
3e: The current node can only contribute either 1 being 1-degree or 3 edges of maximum children for it to be 3 degree with parent edge will become 4 degree.
Here is the exact replica code. I hope it saves you a couple of hours.
Hi can anyone tell me what is wrong in my F submission
I am trying to only consider the nodes whose degree>=4 and for these trees trying to calculate the number of nodes i can pick up so that all the nodes have degree <=4
https://atcoder.jp/contests/abc394/submissions/63070024
please
Can someone from the future tell me how to solve E and F
For E, the key idea is that if you have found the smallest palindromic path from
itoj, then we will try to expand it on both sides and solve for other pairs. So, we can look for another pair(k, l)such thatkconnects toiandjconnects tolusing the same letter and now we have a path of 2 extra characters. We do this in increasing order of length of the found path and construct the answer using BFS.For F, we do a dp on tree. A node in Alkane can either have a parent and then 3 children or be root and have 4 children or be a leaf. For each node, we compute two things: 1. Largest subtree such that this is the root, i.e. has 4 children. ->
most4[node]2. Largest subtree where cur node is a child (can either supply 1 node acting as leaf or a subtree where cur node has 3 children) ->most3[node]Both of these are pretty simple to compute using dfs.
Thanks, I really appreciate it but its been 4 years since i was an expert, can you please tell me in detail? I will be grateful, also what rated problems are these according to you?
my submission
can someone hacks me with my submission? I first find all points with at least 4 degrees and use union-find set to find the maximum number with 4 degrees in the subgraph and then calculate the ans.
I think problem C is harder than problem D. Problem D is very easy.
C is even simpler than D if you see the simple trick: iterate the string in reverse order, then you can actually simply change all "WA" to "AC".
I found that we can change all "WWW...A" to "ACCC...C". So in the end, I solve this problem.
(Maybe my English isn't well...)
My solution is the same as yours but this is not the best way to solve this problem. Just reverse the string is indeed a lot better.
Can I use kmp?
Can someone please point out what's the problem with below logic of E.
Make a reversed graph of the original one. Run a multi-source BFS for each pair (i, j) on both G and reversed G. Move i to next_i following edge (i, next_i) in G and move j to next_j following edge (j, next_j) in reversed G when label of these two edges are the same. Once hitting i == j or C[i][j] != '-' means shortest path is found.