atcoder_official's blog

By atcoder_official, history, 2 years ago, In English

We will hold AtCoder Beginner Contest 378.

We are looking forward to your participation!

  • Vote: I like it
  • +20
  • Vote: I do not like it

| Write comment?
»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope to get to 1200 in this contest.

I am 1190 now.

»
2 years ago, hide # |
 
Vote: I like it -30 Vote: I do not like it

What are you guys f**king? Easy ABCDEF and hard G , 180+ competitors solved F in 40 min.Harder F,Pls!!!!!!

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Any hints regrading E and F ? (Contests have Ended!)

  • »
    »
    2 years ago, hide # ^ |
    ← Rev. 2  
    Vote: I like it -8 Vote: I do not like it

    E:consider ai=(sigma (j from 1 to i) aj)%m and count the pair of i,j which (i<j) and (ai>aj)

    F: consider that the deg of the path will be 2 3 3 3 3...3 3 3 2 and this is a dp

  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    F : all we want is the number of pairs of nodes with degree 2 that have one or more nodes of degree 3 between them

    My approach : divide the tree into connected components that have degree 3 and leaves of degree 2 (easily done using dfs) , now all we have to do is count number of pairs of degree 2 node ( n*(n-1)//2 where n == number of degree 2 leaves connected to current connected component ) add up the answers of all connected components and we are done!

    • »
      »
      »
      2 years ago, hide # ^ |
      ← Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      Help

      Problem ABC378 F: https://atcoder.jp/contests/abc378/tasks/abc378_f

      Hi there,

      Could you/anyone please share the edges which will result in cycle with degree 3 for the below example?

      15
      1 15
      11 14
      2 10
      1 7
      9 8
      6 9
      4 12
      14 5
      4 9
      8 11
      7 4
      1 13
      3 6
      11 10
      Output: 6
      

      I was unable to find all and here is my finding:

      11-14 (already a cycle, given)

      6-10

      6-7

      10-7

      Total: 4

      Thank you in advance.

      • »
        »
        »
        »
        2 years ago, hide # ^ |
        ← Rev. 2  
        Vote: I like it 0 Vote: I do not like it

        8 7

        8 6

        • »
          »
          »
          »
          »
          2 years ago, hide # ^ |
          ← Rev. 3  
          Vote: I like it +1 Vote: I do not like it

          Got it thank you, without your help it wouldn't be possible.

          BTW I've drwan the graph incorrectly.

          Here is my findings, Deg[2] = {10, 14, 8, 6, 7}

          Connecting edges:

          6 -> 10 (cycle with node 8 has deg 2, not possible)
          6 -> 14 (cycle with node 8 has deg 2, not possible)
          6 -> 8
          6 -> 7
          8 -> 7
          10 -> 14
          8 -> 14
          8 -> 10
          

          Conclusion: Edges contributing in the formation cycle requires to have a deg of 3.

  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I think F is a graph problem(apparently),you can use BFS or DFS. Like this:

    //Author:RaShalGul
    #include <bits/stdc++.h>
    #define int long long
    using namespace std;
    const int N=2e5+5;
    int n,k,ans;
    int a[N],l[N];
    vector<int> g[N];
    void dfs(int x,int fa){
    	if(l[x]==2){
    		a[x]=1;
    	}
    	for(int v:g[x]){
    		if(v==fa){
    			continue;
    		}
    		dfs(v,x);
    		ans+=a[x]*a[v]-(l[x]==2&&l[v]==2);
    		if(l[x]==3){
    			a[x]+=a[v];
    		}
    	}
    }
    signed main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(nullptr);
    	cout.tie(nullptr);
    	cin>>n;
    	for(int i=1,x,y;i<n;i++){
    		cin>>x>>y;
    		l[x]++,l[y]++;
    		g[x].emplace_back(y);
    		g[y].emplace_back(x);
    	}
    	dfs(1,0);
    	cout<<ans;
    	return 0;
    }
    

    I solved it after the contest ended,i'm so angry about spending too much time on E.

    P.S.:Sorry about my weak English.

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

how to solve last problem?

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can you guys find the WA problem with my submission for E?

»
2 years ago, hide # |
← Rev. 4  
Vote: I like it 0 Vote: I do not like it

I followed a different approach than the editorial to solve F. First, I merge adjacent nodes that have degree 3 in the original graph. Let $$$A$$$ denote the subset of nodes of the new graph that correspond to a group of adjacent nodes of degree 3 in the original graph. On the new graph the solution is $$$\sum_{v \in A} {cnt_v \choose 2}$$$ where $$$cnt_v$$$ is the number of neighbors of degree 2 of $$$v$$$.

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I think F is much easier than E.

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

https://atcoder.jp/contests/abc378/submissions/59414779 Can someone help me check why my solution for problem E is wrong? I can't figure it out. Thank you!

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I did not get the solution of problem E. Can anyone please explain me the solution of problem E in details ? ( details explanation )

  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    E can be solved using divide and conquer: Let $$$f(l,r)$$$ be the result when considering the array from $$$l$$$ to $$$r$$$. Consider $$$mid=(l+r)/2$$$. We know that $$$f(l,r) = f(l,mid)+f(mid+1,r)\ +$$$ (sum of all arrays formed of by merging a non-empty suffix of $$$[l,mid]$$$ and a non-empty prefix of $$$[mid+1,r]$$$, each array has its sum under modulo $$$M$$$). We take every non-empty prefix of $$$[mid+1,r]$$$, sort them by (their sum modulo $$$M$$$). For each non-empty suffix of $$$[l,mid]$$$, let $$$suf$$$ be the sum of the suffix modulo $$$M$$$, we count the prefixes that have value less than $$$M-suf$$$ directly. Else we subtract the result by $$$M$$$ for each prefix that is greater or equal to $$$M-suf$$$. (since $$$suf$$$ + (a prefix modulo $$$M$$$) is less than $$$2*M-1$$$). To calculate this fast for each suffix we use binary search and prefix sum. Code: https://atcoder.jp/contests/abc378/submissions/59455453. Complexity: $$$O(nlog^2(n))$$$.

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Anyone solved E using divide and conquer?