F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Sparse Graph

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 3607    Accepted Submission(s): 1201


Problem Description
In graph theory, the $complement$ of a graph $ G $ is a graph $ H $ on the same vertices such that two distinct vertices of $ H $ are adjacent if and only if they are $not$ adjacent in $ G $.

Now you are given an undirected graph $ G $ of $ N $ nodes and $ M $ bidirectional edges of $unit$ length. Consider the complement of $G$, i.e., $H$. For a given vertex $ S $ on $ H $, you are required to compute the shortest distances from $ S $ to all $ N-1 $ other vertices.
 

Input
There are multiple test cases. The first line of input is an integer $T(1\le T<35) $ denoting the number of test cases. For each test case, the first line contains two integers $ N(2\le N\le 200000) $ and $ M(0\le M\le 20000) $. The following $ M $ lines each contains two distinct integers $ u, v(1\le u,v\le N) $ denoting an edge. And $ S\ (1\le S\le N) $ is given on the last line.
 

Output
For each of $ T $ test cases, print a single line consisting of $N-1 $ space separated integers, denoting shortest distances of the remaining $ N-1 $ vertices from $ S $ (if a vertex cannot be reached from S, output ``-1" (without quotes) instead) in ascending order of vertex number.
 

Sample Input
1 2 0 1
 

Sample Output
1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 11:38:42, Gzip enabled