Submission #2545869


Source Code Expand

///
// File:  d.go
// Author: ymiyamoto
//
// Created on Tue May 22 00:16:32 2018
//
package main

import (
	"fmt"
)

type node struct {
	to, weight int
}

var N, M int
var vals []int
var graph [][]node

func dfs(root, val int) bool {
	if vals[root] == -(1 << 30) {
		vals[root] = val
	} else {
		if vals[root] != val {
			return false
		}
		return true
	}

	for i := range graph[root] {
		n := graph[root][i]
		to := n.to
		weight := n.weight
		if !dfs(to, vals[root]+weight) {
			return false
		}
	}
	return true
}

func main() {
	fmt.Scan(&N, &M)

	graph = make([][]node, N+1)
	for i := range graph {
		graph[i] = make([]node, 0)
	}

	for i := 0; i < M; i++ {
		var L, R, D int
		fmt.Scan(&L, &R, &D)
		graph[L] = append(graph[L], node{to: R, weight: D})
		graph[R] = append(graph[R], node{to: L, weight: -D})
	}

	vals = make([]int, N+1)
	for i := range vals {
		vals[i] = -(1 << 30)
	}

	for i := 1; i <= N; i++ {
		if vals[i] == -(1<<30) && !dfs(i, 0) {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

Submission Info

Submission Time
Task D - People on a Line
User mohei
Language Go (1.6)
Score 0
Code Size 1089 Byte
Status TLE
Exec Time 2108 ms
Memory 37504 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 5
AC × 36
TLE × 11
Set Name Test Cases
Sample sample01.txt, sample02.txt, sample03.txt, sample04.txt, sample05.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, sample01.txt, sample02.txt, sample03.txt, sample04.txt, sample05.txt
Case Name Status Exec Time Memory
01.txt TLE 2104 ms 17284 KB
02.txt TLE 2108 ms 17024 KB
03.txt TLE 2108 ms 16256 KB
04.txt TLE 2104 ms 15872 KB
05.txt AC 1987 ms 15488 KB
06.txt AC 1636 ms 20352 KB
07.txt AC 1918 ms 14980 KB
08.txt AC 1537 ms 21120 KB
09.txt AC 1382 ms 16000 KB
10.txt AC 1326 ms 19456 KB
11.txt AC 1378 ms 15488 KB
12.txt AC 1609 ms 13824 KB
13.txt AC 1832 ms 18688 KB
14.txt AC 1435 ms 15872 KB
15.txt AC 1597 ms 14080 KB
16.txt AC 1449 ms 19072 KB
17.txt TLE 2067 ms 29440 KB
18.txt AC 1923 ms 15488 KB
19.txt AC 1547 ms 21380 KB
20.txt AC 1541 ms 16896 KB
21.txt TLE 2056 ms 19200 KB
22.txt AC 1549 ms 16768 KB
23.txt TLE 2055 ms 19968 KB
24.txt AC 1556 ms 16640 KB
25.txt TLE 2108 ms 14592 KB
26.txt TLE 2069 ms 29184 KB
27.txt AC 1280 ms 27264 KB
28.txt AC 1567 ms 21248 KB
29.txt AC 1296 ms 37504 KB
30.txt AC 1458 ms 19328 KB
31.txt AC 1264 ms 25088 KB
32.txt AC 1452 ms 19328 KB
33.txt TLE 2104 ms 14720 KB
34.txt TLE 2065 ms 23040 KB
35.txt AC 1263 ms 25216 KB
36.txt AC 1527 ms 14336 KB
37.txt AC 1257 ms 27136 KB
38.txt AC 1453 ms 19200 KB
39.txt AC 1231 ms 12032 KB
40.txt AC 1442 ms 15872 KB
41.txt AC 8 ms 3712 KB
42.txt AC 742 ms 12672 KB
sample01.txt AC 1 ms 512 KB
sample02.txt AC 1 ms 512 KB
sample03.txt AC 1 ms 512 KB
sample04.txt AC 1 ms 512 KB
sample05.txt AC 1 ms 512 KB