Submission #32649747


Source Code Expand

N = gets.to_i
B = Array.new(N+1){[]}
E = [[]]+(N-1).times.map{
	gets.split.map(&:to_i).tap{|a,b|
		B[a]<<b
		B[b]<<a
	}
}

L = [nil]*(N+1)
R = [nil]*(N+1)
i = -1
*Q = 1
while a = Q.pop
	if ! L[a]
		L[a] = i += 1
		Q<<a
		Q.concat B[a].select{|b| ! L[b] }
	else
		R[a] = i += 1
	end
end

S = [0]*(i+1)
Q = gets.to_i
Q.times{
	t,e,x,y = *gets.split.map(&:to_i),0
	a,b = E[e].rotate t
	if L[a]<L[b]
		S[L[b]] += x
		S[R[b]] -= x
	else
		S[0] += x
		S[L[a]] -= x
		S[R[a]] += x
	end
}
s = 0
S.map!{|x| s += x }

puts L[1..N].map{|i| S[i] }

Submission Info

Submission Time
Task E - Through Path
User ds14050
Language Ruby (2.7.1)
Score 500
Code Size 577 Byte
Status AC
Exec Time 832 ms
Memory 59756 KiB

Compile Error

./Main.rb:27: warning: assigned but unused variable - y

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 36
Set Name Test Cases
Sample 01_sample.txt, 02_sample.txt, 03_sample.txt
All 01_sample.txt, 02_sample.txt, 03_sample.txt, 04_small.txt, 05_small.txt, 06_small.txt, 07_small.txt, 08_small.txt, 09_small.txt, 10_small.txt, 11_small.txt, 12_small.txt, 13_small.txt, 14_small.txt, 15_small.txt, 16_small.txt, 17_small.txt, 18_small.txt, 19_small.txt, 20_small.txt, 21_small.txt, 22_small.txt, 23_small.txt, 24_large.txt, 25_large.txt, 26_large.txt, 27_max.txt, 28_max.txt, 29_max.txt, 30_path.txt, 31_path.txt, 32_path.txt, 33_star.txt, 34_star.txt, 35_star.txt, 36_star.txt
Case Name Status Exec Time Memory
01_sample.txt AC 54 ms 14208 KiB
02_sample.txt AC 55 ms 14116 KiB
03_sample.txt AC 56 ms 14272 KiB
04_small.txt AC 59 ms 14212 KiB
05_small.txt AC 59 ms 14240 KiB
06_small.txt AC 56 ms 14108 KiB
07_small.txt AC 56 ms 14280 KiB
08_small.txt AC 55 ms 14164 KiB
09_small.txt AC 60 ms 14068 KiB
10_small.txt AC 57 ms 14176 KiB
11_small.txt AC 54 ms 14292 KiB
12_small.txt AC 58 ms 14192 KiB
13_small.txt AC 54 ms 14152 KiB
14_small.txt AC 56 ms 14308 KiB
15_small.txt AC 58 ms 14200 KiB
16_small.txt AC 56 ms 14256 KiB
17_small.txt AC 55 ms 14292 KiB
18_small.txt AC 56 ms 14216 KiB
19_small.txt AC 58 ms 14288 KiB
20_small.txt AC 61 ms 14168 KiB
21_small.txt AC 57 ms 14228 KiB
22_small.txt AC 56 ms 14208 KiB
23_small.txt AC 55 ms 14224 KiB
24_large.txt AC 678 ms 47920 KiB
25_large.txt AC 649 ms 45520 KiB
26_large.txt AC 262 ms 24044 KiB
27_max.txt AC 825 ms 59756 KiB
28_max.txt AC 819 ms 59676 KiB
29_max.txt AC 832 ms 59584 KiB
30_path.txt AC 808 ms 57020 KiB
31_path.txt AC 812 ms 57180 KiB
32_path.txt AC 809 ms 59684 KiB
33_star.txt AC 798 ms 58640 KiB
34_star.txt AC 795 ms 58308 KiB
35_star.txt AC 796 ms 58316 KiB
36_star.txt AC 818 ms 58552 KiB