작은 K 농장
3215 단어 도 론
http://www.lydsy.com/JudgeOnline/problem.php?id=3436
해제
물 문 제 를 풀 고 긴 장 된 신경 을 풀다.계차 구속 건 도 최 장 거리.뭐? 이렇게 많아?첫 번 째 는 DFS 버 전의 spfa, 두 번 째 는 BFS 버 전의 spfa 다.
코드
//
#include
#include
#include
#define maxn 100000
using namespace std;
int N, M, head[maxn], to[maxn], cnt[maxn], w[maxn], vis[maxn], nex[maxn], dist[maxn],
tot, ans;
inline void adde(int a, int b, int v)
{to[++tot]=b;w[tot]=v;nex[tot]=head[a];head[a]=tot;}
bool spfa(int pos)
{
int p;
vis[pos]=1;
for(p=head[pos];p;p=nex[p])
{
if(dist[to[p]]if(vis[to[p]])return false;
if(!spfa(to[p]))return false;
}
}
vis[pos]=0;
return true;
}
int main()
{
int i, a, b, c, type;
scanf("%d%d",&N,&M);
for(i=1;i<=M;i++)
{
scanf("%d%d%d",&type,&a,&b);
if(type==3){adde(a,b,0),adde(b,a,0);continue;}
scanf("%d",&c);
if(type==2)swap(a,b),c=-c;
adde(a,b,c);
}
for(i=1;i<=N;i++)
{
if(!spfa(i))
{
printf("No");
return 0;
}
}
printf("Yes");
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
HDU 1874: 원활 한 공사 계속 [Dijkstra & SPFA & Floyd]모 성 은 여러 해 동안 의 원활 한 공사 계획 을 실행 한 후에 마침내 많은 길 을 건설 하 였 다.길 을 많이 건 너 지 않 아 도 좋 지 않다. 한 도시 에서 다른 도시 로 갈 때마다 여러 가지 도로 방안 을 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.