Submission #3230599
Source Code Expand
#include <bits/stdc++.h> using namespace std ; #define N 500010 #define inf 0x3f3f3f3f int head[ N ] , cnt ; int d[ N ] , vis[ N ] , q[ N ] ; int n , m ; struct node { int to , nxt , v ; }e[ N ] ; void ins( int u , int v , int w ) { e[ ++ cnt ].to = v ; e[ cnt ].nxt = head[ u ] ; e[ cnt ].v = w ; head[ u ] = cnt ; } map<pair<int,int>,int>mp; int tot = 0 ; int get_num( int x , int y ) { if( !mp.count( make_pair( x , y ) ) ) mp[ make_pair( x , y ) ] = ++tot ; return mp[ make_pair( x , y ) ] ; } void spfa() { for( int i = 1 ; i <= tot ; i ++ ) d[ i ] = inf ; vis[ 1 ] = q[ 1 ] = 1 ; d[ 1 ] = 0 ; int l = 1 , r = 2 ; while( l < r ) { int u = q[ l ++ ] ; vis[ u ] = 0 ; for( int i = head[ u ] ; i ; i = e[ i ].nxt ) { int v = e[ i ].to ; if( d[ v ] > d[ u ] + e[ i ].v ) { d[ v ] = d[ u ] + e[ i ].v ; if( !vis[ v ] ) vis[ v ] = 1 , q[ r ++ ] = v ; } } } if( d[ n ] == inf ) puts( "-1" ) ; else printf( "%d\n" , d[ n ] / 2 ) ; } int main() { scanf( "%d%d" , &n , &m ) ; tot = n ; for( int i = 1 ; i <= m ; i ++ ) { int x , y , c ; scanf( "%d%d%d" , &x , &y , &c ) ; int n1 = get_num( x , c ) , n2 = get_num( y , c ) ; ins( x , n1 , 1 ) ; ins( n1 , x , 1 ) ; ins( n1 , y , 1 ) ; ins( y , n1 , 1 ) ; ins( n1 , n2 , 0 ) ; ins( n2 , n1 , 0 ) ; } spfa() ; }
Submission Info
Submission Time | |
---|---|
Task | E - Snuke's Subway Trip |
User | henry_y |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1392 Byte |
Status | RE |
Exec Time | 588 ms |
Memory | 38272 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:52:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf( "%d%d" , &n , &m ) ; ^ ./Main.cpp:56:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf( "%d%d%d" , &x , &y , &c ) ; ^
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 600 | ||||||
Status | AC |
|
Set Name | Test Cases |
---|---|
Sample | |
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, sample_01.txt, sample_02.txt, sample_03.txt, w1.txt, w10.txt, w11.txt, w12.txt, w13.txt, w14.txt, w15.txt, w16.txt, w17.txt, w18.txt, w2.txt, w3.txt, w4.txt, w5.txt, w6.txt, w7.txt, w8.txt, w9.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 3 ms | 8448 KB |
02.txt | WA | 112 ms | 18176 KB |
03.txt | RE | 412 ms | 38272 KB |
04.txt | RE | 408 ms | 38016 KB |
05.txt | RE | 373 ms | 30848 KB |
06.txt | RE | 265 ms | 25472 KB |
07.txt | RE | 272 ms | 25472 KB |
08.txt | RE | 394 ms | 38272 KB |
09.txt | RE | 281 ms | 27776 KB |
10.txt | RE | 284 ms | 27776 KB |
11.txt | WA | 157 ms | 21504 KB |
12.txt | WA | 36 ms | 12544 KB |
13.txt | WA | 72 ms | 15744 KB |
14.txt | WA | 150 ms | 21120 KB |
15.txt | RE | 205 ms | 17664 KB |
16.txt | WA | 135 ms | 19840 KB |
17.txt | WA | 163 ms | 22144 KB |
18.txt | WA | 54 ms | 13696 KB |
19.txt | WA | 506 ms | 17536 KB |
20.txt | RE | 252 ms | 23168 KB |
21.txt | RE | 378 ms | 37120 KB |
22.txt | WA | 186 ms | 24320 KB |
23.txt | RE | 315 ms | 29696 KB |
24.txt | WA | 144 ms | 22144 KB |
25.txt | WA | 33 ms | 12544 KB |
26.txt | WA | 57 ms | 14720 KB |
27.txt | WA | 167 ms | 24320 KB |
28.txt | RE | 238 ms | 22784 KB |
29.txt | WA | 158 ms | 23552 KB |
30.txt | WA | 140 ms | 21504 KB |
31.txt | WA | 57 ms | 14848 KB |
32.txt | WA | 588 ms | 16512 KB |
33.txt | WA | 162 ms | 23936 KB |
34.txt | RE | 212 ms | 17664 KB |
35.txt | WA | 31 ms | 12544 KB |
36.txt | WA | 54 ms | 13696 KB |
37.txt | RE | 224 ms | 18176 KB |
38.txt | RE | 212 ms | 17664 KB |
sample_01.txt | AC | 3 ms | 8448 KB |
sample_02.txt | AC | 3 ms | 8448 KB |
sample_03.txt | AC | 2 ms | 6400 KB |
w1.txt | WA | 224 ms | 17792 KB |
w10.txt | WA | 322 ms | 36864 KB |
w11.txt | WA | 49 ms | 12672 KB |
w12.txt | WA | 73 ms | 13824 KB |
w13.txt | WA | 123 ms | 19584 KB |
w14.txt | WA | 294 ms | 33920 KB |
w15.txt | WA | 31 ms | 12544 KB |
w16.txt | WA | 43 ms | 12544 KB |
w17.txt | WA | 62 ms | 13056 KB |
w18.txt | WA | 94 ms | 16896 KB |
w2.txt | WA | 258 ms | 17664 KB |
w3.txt | WA | 177 ms | 21248 KB |
w4.txt | WA | 352 ms | 18944 KB |
w5.txt | WA | 288 ms | 35328 KB |
w6.txt | WA | 216 ms | 22144 KB |
w7.txt | RE | 346 ms | 33792 KB |
w8.txt | WA | 274 ms | 34048 KB |
w9.txt | WA | 282 ms | 34432 KB |