## algorithms – Find the number of pairs of vertices that create more cycle

I am new to Competitive Programming and I have a Graph problem as below, the limit of time is 3 seconds and the memory limit is 256 Mb.

An is observing an undirected graph. He wonders if there exits in this
graph 2 vertices that connecting these 2 vertices will create exactly
one more simple cycle. Recall that a simple cycle may be defined
either as a sequence of vertices with no repetitions of vertices and
edges allowed, other than the repetition of the starting and ending
vertex, with each two consecutive vertices in the sequence adjacent to
each other in the graph.

Your task is to help An count the number of pairs of vertices
satisfying the conditions above.

Input

The first line consist of two positive integers n,m (n,m≤10^5)
which are the number of vertices and the number of edges of the given
graph.

Each line in the m following lines contains two positive integers u,v
(u,v≤n) which are two vertices connected by an edge.

Output

You should output on a single line an unique integer that is
the number of pairs you found.

I am now having no idea about the way to solve this problem because I do not find any properties of pair-vertices which create more simple cycle in a given graph. I really need your help to build a proper algorithms.

I have a sample test case as below:

Input

5 4

1 2

2 3

3 4

4 5

Output

6

## How to find cycle of length 4 in O(MsqrtM)

I know it’s possible cuz some red Chinese guy on codeforces said it was. I know how to do it in O(N^3) with 1/64 constant using bitset. I also would like to know how to do it in O(N*M), such a complexity was mentioned in another blog here.

## testing – Relation between Quality Assurnce and Software Development Life Cycle

Quality Assurance(QA) always go for doing right with right plan. QA verifies the validated test result.
My questions are:

Testing strategies fall under SDLC or QA ?

How Quality Assurance
and Software Development Life Cycle(SDLC) are related?

This question is posted on stack overflow and closed for off topic,and referred to ask here.

## python 3.x – Cyclic generator with access to current local state and executes callback after each cycle

I’m working on a Python class that is a cyclic generator, like `itertools.cycle`, but it offers access to its current state and executes a callback after the completion of each cycle.

I’m looking for feedback on the way I’ve implemented this so that I might improve it or find a better way.

In this version, I’ve used `itertools.cycle`, but I’m wondering if there might be any advantage to subclassing `collections.abc.Iterator` and building it from the ground up. My thoughts are that I might be able to improve performance by using modulus division to constrain the output, without the overhead of importing other libraries. My primary use for this will be to drive other clocks, so timing is crucial.

I’m also unsure if this is the best way to implement the callback. It works and is simple, but I’m interested in the opinions and experience of others regarding this feature.

All guidance and opinions welcomed!

Thanks!

``````from itertools import cycle
from functools import partial
from typing import Callable, Optional, Tuple

class EventClock:
executes a callback at the start/end of each cycle """
def __init__(self, size: int, callback: Callable, args: Optional(Tuple)=None):
self._size = size
self._position = 0
self._loop = cycle(range(1, size + 1))
self._callback = partial(callback, *args)

def __repr__(self):
return f"<_class {type(self).__name__}(size={self._size}, position={self._position})_>"

@property
def nextstep(self):
self._position = next(self._loop)
if self._position == 1:
self._callback()
return self._position

@property
def position(self):
return self._position

@property
def reset(self):
"""reset generator's currrent state to -1"""
for index in self.meter:
if index == self.length:
break
``````

## detection of cycle in a graph c#

can someone recommend me some articles related to the topic finding cycles in a graph, I am working on this topic and I need more resources to search from?

## at.algebraic topology – Find the representative cycle location in the persistence diagram

I know that some toolbox such as Dionysus can also return the representative points which are on the boundaries of the cycles (topological features of a point cloud). I can clearly extract these points using the TDA toolbox in R which acts as a wrapper on the Dionysus and several other TDA toolbox. However, I wonder what is the theory behind it. Can someone please explain it in short or guide me to the papers where I can read more about it. I’m familiar with the reduced boundary matrix and how it is possible to compute the persistence homology using this matrix, however, I’m curious if Dionysus takes advantage of this matrix to detect the boundaries.

## algorithms – Cubic Cycle is Np-Complete

HAMCYCLE = {<“G”> : G is a simple undirected
graph that has a Hamiltonian cycle}

CUBIC CYCLE = {<“G”> :G is a simple undirected graph that contains
a simple cycle of length at least |V (G)|^1/3}

The reduction i figured out is :
G has a ham-cycle <==> G has a cubic cycle of a given length(V^1/3).
Prooving ==> part is simple as we have to show that if a cycle of V exists, then in G a cycle of V^1/3 exists.
But i got stuck in proving the other direction.

## maximum Hamilton cycle and NP-completeness

we know max tsp (maximal Hamilton cycle) is NP-Hard. is there any decision version for this problem to conclude this is NP-Complete?

## android – how to handle dependency cycle dagger 2

I have two classes `PdfTicketStorage` and `OfflineHelper` they both depend on each other.

OfflineHelper class requires PdfTicketStorage to send data to firebase

``````class OfflineHelper @Inject constructor(
private val app: App,
private val settings: Settings,
private val pdfTicketStorage: PdfTicketStorage,
) {
private fun postPrintedTicket(offlineData: OfflineData) {
//SENDS DATA TO FIREBASE
val offlinePrintedTicketInfo = gson.fromJson(offlineData.requestInfoJson, OfflinePrintedTicketInfo::class.java)
pdfTicketStorage.store(offlinePrintedTicketInfo.pdfTicketFilePath, offlinePrintedTicketInfo.pdfTicketContent)
}

fun saveOfflineDataWithPdf() {
//save data to database
}
}
``````

PdfTicketStorage requires offlineHelper to save data in the database

``````public class PdfTicketStorage {

private final String cloudStorageBucket;
private final OfflineHelper offlineHelper;

public PdfTicketStorage(String cloudStorageBucket, OfflineHelper offlineHelper) {
this.cloudStorageBucket = cloudStorageBucket;
this.offlineHelper = offlineHelper;
}

public Single<String>  storeTest(final String filePath, final byte() fileContents, final String fuelOrderId) {
offlineHelper.saveOfflineDataWithPdf();
return Single.just("");

}
}
``````

As both are interdependent how can resolve the dependency cycle

error i get

``````(Dagger/DependencyCycle) Found a dependency cycle:
public interface AppComponent {
^
com.xx.xxx.clean.offline.OfflineHelper is injected at
com.xx.xxx.injection.modules.ServiceModule.providePdfTicketStorage(…, offlineHelper)
com.xx.xxx.printing.storage.PdfTicketStorage is injected at
com.xx.xxx.clean.offline.OfflineHelper(…, pdfTicketStorage, …)
com.xx.xxx.clean.offline.OfflineHelper is injected at
com.xx.xxx.activities.MainActivity.offlineHelper
com.xx.xxx.activities.MainActivity is injected at
com.xxx.xx.injection.components.ActivityComponent.inject(com.xx.xxx.activities.MainActivity) (com.xx.xxx.injection.components.AppComponent → com.xx.xxx.injection.components.ActivityComponent)
``````

ServiceModule

``````  @Provides @PerApp
public PdfTicketStorage providePdfTicketStorage(App app, OfflineHelper offlineHelper) {
return new PdfTicketStorage(app.getString(R.string.cloud_storage_bucket), offlineHelper);
}
``````

Could you suggest any alternatives to fix this please

thanks
R

## complexity theory – NP-complete problem of partitioning into several sets with a Hamiltonian cycle

How to prove the $$NP$$-completeness of the language $$L$$ = $${(G, k)$$: the vertices of an undirected graph $$G$$ can be partitioned into $$k$$ pairwise disjoint sets of pairwise different sizes so,
that all the corresponding induced subgraphs have a Hamiltonian cycle}.
I had no problems how to prove that this language is in the $$NP$$, but it is not clear to me how to prove that this language is in the $$NP-hard$$ class.