I think this is a great approach. As a training contest, problem F is much easier than problem E, and is the one of the the only three problems with data in the contest. That is our MX (Dream Bear), an OI training institution in China.
When I see this kind of constraint, I tend to think of bitset, which leads to the following two ideas.
Approach 1: Consider n bitsets b_i of size n\times m that maintain which numbers appear in each row. So enumerate (i,j) and update the answer to the pair if |b_i\cup b_j|=m\times2. The time complexity and space complexity are \mathcal{O}(\frac{n^3m}w).
Approach 2: Consider n\times m bitsets b_i of size n that maintain on which lines each number has appeared. For all (i,j) that satisfies the condition there must be i\not\in b_{a_{j,k}} for all k. From this, think of enumerating i and taking the complement t of the union set of all b_{a_{i,k}}, then for legitimate j there is j\in t. Since the answer is required to be minimal, each row can be sorted by w_i, and the optimal j is \text{lowbit}(t). Time complexity \mathcal{O}(n\log n+\frac{n^2m}w), space complexity \mathcal{O}(\frac{n^2m}w).
Approach 1 is certainly not promising, and is not even as good as the plain analog \mathcal{O}(n^2m). But we also wanted to use bitset to solve this problem, so we considered optimizing approach two. Observe that this can be a waste of time and space if a number appears only once in all rows, i.e., |b_x|=1. This example reminds us that it is better to calculate the contribution of x directly for fewer occurrences, and consider maintaining |b_x|\le\sqrt{nm} directly in a vector instead of a bitset.
This can be done with time complexity \mathcal{O}(n\log n+nm+(nm-\sqrt{nm})^2\frac nw) and space complexity \mathcal{O}(\frac{n\sqrt{nm}}w+nm).