Submission #6128255


Source Code Expand

Copy
import sys
input = sys.stdin.readline

N,M = map(int,input().split())
if M == 0:
  print(N-1)
  exit()
from scipy.sparse import *
import numpy as np
AB = np.array([input().split() for _ in range(M)], dtype = np.int32)

AB -= 1 # 0-indexed
graph = csr_matrix((np.ones(M), (AB[:,0], AB[:,1])), shape=(N,N))

x, _ = csgraph.connected_components(graph)
answer = x - 1 # 連結成分をx個から1個に減らす
print(answer)

Submission Info

Submission Time
Task B - 道路工事
User maspy
Language Python (3.4.3)
Score 100
Code Size 439 Byte
Status AC
Exec Time 291 ms
Memory 48408 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 22
Set Name Test Cases
Sample sample1.txt, sample2.txt
All 0.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt
Case Name Status Exec Time Memory
0.txt AC 17 ms 3060 KB
1.txt AC 17 ms 3060 KB
10.txt AC 241 ms 17448 KB
11.txt AC 165 ms 13648 KB
12.txt AC 17 ms 3060 KB
13.txt AC 165 ms 13628 KB
14.txt AC 171 ms 13728 KB
15.txt AC 277 ms 46588 KB
16.txt AC 17 ms 3060 KB
17.txt AC 171 ms 14892 KB
18.txt AC 174 ms 14844 KB
19.txt AC 291 ms 48408 KB
2.txt AC 17 ms 3060 KB
3.txt AC 17 ms 3060 KB
4.txt AC 17 ms 3060 KB
5.txt AC 170 ms 13720 KB
6.txt AC 170 ms 13720 KB
7.txt AC 166 ms 13720 KB
8.txt AC 17 ms 3060 KB
9.txt AC 167 ms 13628 KB
sample1.txt AC 166 ms 13676 KB
sample2.txt AC 164 ms 13620 KB