Binomial Coefficient

This commit is contained in:
Hizenberg
2024-04-10 15:36:18 +05:30
parent 6ddf41feb5
commit bc8374182f
21 changed files with 810 additions and 769 deletions

View File

@@ -1,19 +1,19 @@
vector<int> dist(n+1,(int)-1e17);
dist[1]=0;
for(int i = 1 ; i < n ; i++ ){
for(auto& e : g ){
int a,b,w;
tie(a,b,w)=e;
dist[b]=max(dist[b],dist[a]+w);
}
}
for(auto& e : g ){
int a,b,w;
tie(a,b,w)=e;
if( dist[b] < dist[a] + w ){
cycle[b]=true;
}
vector<int> dist(n+1,(int)-1e17);
dist[1]=0;
for(int i = 1 ; i < n ; i++ ){
for(auto& e : g ){
int a,b,w;
tie(a,b,w)=e;
dist[b]=max(dist[b],dist[a]+w);
}
}
for(auto& e : g ){
int a,b,w;
tie(a,b,w)=e;
if( dist[b] < dist[a] + w ){
cycle[b]=true;
}
}

View File

@@ -1,7 +1,7 @@
for(int k = 1 ; k <= n ; k++ ){
for(int i = 1 ; i <= n ; i++ ){
for(int j = 1 ; j <= n ; j++ ){
dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
}
}
for(int k = 1 ; k <= n ; k++ ){
for(int i = 1 ; i <= n ; i++ ){
for(int j = 1 ; j <= n ; j++ ){
dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
}
}
}

View File

@@ -1,17 +1,17 @@
priority_queue<pii> q;
q.push({0,1});
dist[1]=0;
while(!q.empty()){
pii n=q.top();q.pop();
int weight=n.F,node=n.S;
if( vis[node] )continue;
vis[node]=true;
for(pii& nbr : g[node]){
int n_nbr=nbr.F,n_w=nbr.S;
if( dist[node]+n_w<dist[n_nbr] ){
dist[n_nbr]=dist[node]+n_w;
q.push({-dist[n_nbr],n_nbr});
}
}
priority_queue<pii> q;
q.push({0,1});
dist[1]=0;
while(!q.empty()){
pii n=q.top();q.pop();
int weight=n.F,node=n.S;
if( vis[node] )continue;
vis[node]=true;
for(pii& nbr : g[node]){
int n_nbr=nbr.F,n_w=nbr.S;
if( dist[node]+n_w<dist[n_nbr] ){
dist[n_nbr]=dist[node]+n_w;
q.push({-dist[n_nbr],n_nbr});
}
}
}