#include #include #include #include #define MAX_SIZE 5200 #define MAX_NODE 501 typedef struct { int start; int end; int time; } Edge; int main() { int T; scanf("%d", &T); Edge* edge = (Edge*)malloc(sizeof(Edge)*MAX_SIZE); int* distance = (int*)malloc(sizeof(int)*MAX_NODE); while(T--) { int N, M, W; scanf("%d %d %d",&N, &M, &W); // ROAD for(int i=0; i<2*M; i+=2) { int S, E, T; scanf("%d %d %d",&S, &E, &T); Edge temp1 = {S, E, T}; Edge temp2 = {E, S, T}; edge[i] = temp1; edge[i+1] = temp2; } // WORM HOLE for(int i=0; i distance[s] + t) { distance[e] = distance[s] + t; if(n==N-1) { negative_cycle = true; break; } } } } printf("%s\n", negative_cycle ? "YES" : "NO"); } free(edge); free(distance); return 0; }