Блог пользователя atcoder_official

Автор atcoder_official, история, 18 месяцев назад, По-английски

We will hold AtCoder Beginner Contest 376.

We are looking forward to your participation!

  • Проголосовать: нравится
  • +91
  • Проголосовать: не нравится

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

The first three questions this time...

»
18 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится -45 Проголосовать: не нравится

$$$\Huge\text{ABC376 RP++!}$$$

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Good Luck & Have Fun!

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What's wrong with my code for D ???

//Author:RasShalGul
#include <bits/stdc++.h>
#define int long long
using namespace std;
int find_minimum_cycle(int N,int M,vector<pair<int,int>>&edges){
	vector<vector<int>>graph(N+1);
	for(const auto& edge:edges){
		graph[edge.first].push_back(edge.second);
	}
	vector<int>dist(N+1,-1);
	vector<int>parent(N+1,-1);
	queue<int>q;
	q.push(1);
	dist[1]=0;
	int min_cycle_length=LONG_LONG_MAX;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int v:graph[u]){
			if(dist[v]==-1){
				dist[v]=dist[u]+1;
				parent[v]=u;
				q.push(v);
			}else if(v!=parent[u]){
				min_cycle_length=min(min_cycle_length,dist[u]+dist[v]+1);
			}
		}
	}
	return (min_cycle_length==LONG_LONG_MAX)?-1:min_cycle_length;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int N,M;
	cin>>N>>M;
	vector<pair<int,int>>edges(M);
	for(int i=0;i<M;i++){
		cin>>edges[i].first>>edges[i].second;
	}
	int result=find_minimum_cycle(N,M,edges);
	cout<<result<<"\n";
	return 0;
}
»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

F is a nice problem, thanks.

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится -30 Проголосовать: не нравится

G is the answer of https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=247&page=show_problem&problem=3646 divides $$$\sum_{i}a_i$$$.

WHAT are you doing,Mr.Atcoder?

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hii,

Did anyone tried to solve D with dfs for cycle detection in directed graph?I tried but it is failing for half of the test cases.I know it is not efficient solution but just wanted to find the case where it can fail

Link to my submission

Thanks

  • »
    »
    18 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Let's say the graph contains two cycles. First 1->2->4->1 and Second 1->2->3->4->1. Since you are performing dfs it may be possible that you explore the second cycle first and thus all of 1,2,3 and 4 will be marked visited. Now you can no longer explore the first cycle as while trying to branch to node 4 from node 2, you will find that node 4 has already been visited. In all such scenarios you will not get the cycle with minimum edges.

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve D if the graph was undirected?

  • »
    »
    18 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Currently I just have $$$O(n^2logn)$$$ solution. I will post again if I got better solution.

    Let $$$S$$$ be the set of nodes which are directly connected to $$$1$$$ and remove all the direct edges between $$$1$$$ and $$$s$$$ where s belongs to $$$S$$$. After that our task is to find the value of $$$min(dis(i,j))+2$$$, where $$$i,j$$$ belongs to set $$$S$$$ and $$$dis(i,j)$$$ means distance between nodes $$$i$$$ and $$$j$$$. which can be done in $$$O(n^2logn)$$$.

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

It would be nice to have a separate leaderboard for rated/unrated participants similar to what Codeforces has with a checkbox "show unofficial".

snuke Do you know if a single leaderboard is intentional or there're plans to implement something similar to what I've described?

»
18 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

In problem D. How could more than a cycle contain the same vertex if the vertices each have a single outgoing edge? At least that's what I interpreted by the problem statement

  • »
    »
    18 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    There's no condition in the statement that the outgoing edge has to be single. It just says: "There is a simple directed graph with N vertices numbered from 1 to N and M edges. The i-th edge (1≤i≤M) is a directed edge from vertex a_i to vertex b_i".

    FWIW, this blog which conveniently was in "Recent actions" just before the start of the Atcoder round helped me to solve this problem — although final solution requires a small modification to the original graph.

»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why is this the initialization of the dp in problem F?

int ph = 0, pp = 0;
dp.assign(Q + 1, vector<int>(N, INF));
dp[0][1] = 0;

This assumes that the other hand is at position 1, but it could be at 0, shouldn't it depend on the first query?