Submission #3226578
Source Code Expand
#include <bits/stdc++.h> using namespace std ; #define N 500010 #define inf 0x3f3f3f3f #define int long long struct node { int to , nxt , belong ; }e[ N << 2 ]; int n , m ; int head[ N << 2 ] , cnt ; int d[ N * 2 ] , vis[ N * 2 ] ; int q[ N * 10 ] ; void ins( int u , int v , int c ) { e[ ++ cnt ].to = v ; e[ cnt ].nxt = head[ u ] ; e[ cnt ].belong = c ; head[ u ] = cnt ; } std::set< int > st[ N ] ; void spfa() { memset( d , inf , sizeof( d ) ) ; q[ 1 ] = vis[ 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 , num = d[ u ] + ( !st[ u ].count( e[ i ].belong ) ) ; if( d[ v ] > num ) { d[ v ] = num ; st[ v ].clear() ; st[ v ].insert( e[ i ].belong ) ; if( ! vis[ v ] ) vis[ v ] = 1 , q[ r ++ ] = v ; }else if( d[ v ] == num ) { st[ v ].insert( e[ i ].belong ) ; } } } if( d[ n ] == inf ) puts( "-1" ) ; else printf( "%lld\n" , d[ n ] ) ; } main() { scanf( "%lld%lld" , &n ,&m ) ; for( int i = 1 ; i <= m ; i ++ ) { int x , y , c ; scanf( "%lld%lld%lld" , &x , &y , &c ) ; ins( x , y , c ) ; ins( y , x , c ) ; } 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 | 1275 Byte |
Status | WA |
Exec Time | 135 ms |
Memory | 58752 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:52:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf( "%lld%lld" , &n ,&m ) ; ^ ./Main.cpp:55:42: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf( "%lld%lld%lld" , &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 | 13 ms | 39168 KB |
02.txt | AC | 75 ms | 50304 KB |
03.txt | AC | 102 ms | 56320 KB |
04.txt | WA | 61 ms | 49408 KB |
05.txt | WA | 135 ms | 58112 KB |
06.txt | AC | 53 ms | 49920 KB |
07.txt | AC | 64 ms | 50176 KB |
08.txt | AC | 100 ms | 56320 KB |
09.txt | AC | 61 ms | 50176 KB |
10.txt | AC | 61 ms | 50176 KB |
11.txt | AC | 89 ms | 55680 KB |
12.txt | AC | 60 ms | 49408 KB |
13.txt | AC | 75 ms | 52608 KB |
14.txt | AC | 91 ms | 56192 KB |
15.txt | WA | 77 ms | 53376 KB |
16.txt | AC | 86 ms | 55296 KB |
17.txt | AC | 92 ms | 56576 KB |
18.txt | AC | 66 ms | 50304 KB |
19.txt | AC | 85 ms | 55296 KB |
20.txt | AC | 101 ms | 57344 KB |
21.txt | AC | 104 ms | 56192 KB |
22.txt | WA | 90 ms | 55808 KB |
23.txt | AC | 103 ms | 56192 KB |
24.txt | AC | 81 ms | 54912 KB |
25.txt | AC | 58 ms | 49536 KB |
26.txt | AC | 74 ms | 52864 KB |
27.txt | AC | 98 ms | 58112 KB |
28.txt | AC | 88 ms | 56448 KB |
29.txt | AC | 96 ms | 56832 KB |
30.txt | AC | 82 ms | 54912 KB |
31.txt | AC | 79 ms | 53504 KB |
32.txt | AC | 74 ms | 53376 KB |
33.txt | AC | 94 ms | 57344 KB |
34.txt | AC | 90 ms | 53504 KB |
35.txt | AC | 56 ms | 49408 KB |
36.txt | AC | 64 ms | 50304 KB |
37.txt | AC | 92 ms | 53888 KB |
38.txt | AC | 90 ms | 53504 KB |
sample_01.txt | AC | 13 ms | 39168 KB |
sample_02.txt | AC | 13 ms | 39168 KB |
sample_03.txt | WA | 13 ms | 39168 KB |
w1.txt | AC | 90 ms | 55296 KB |
w10.txt | WA | 72 ms | 51584 KB |
w11.txt | AC | 84 ms | 49536 KB |
w12.txt | AC | 91 ms | 50304 KB |
w13.txt | AC | 76 ms | 50816 KB |
w14.txt | WA | 79 ms | 53120 KB |
w15.txt | AC | 63 ms | 49408 KB |
w16.txt | AC | 66 ms | 49408 KB |
w17.txt | AC | 69 ms | 49792 KB |
w18.txt | AC | 72 ms | 50816 KB |
w2.txt | AC | 88 ms | 55296 KB |
w3.txt | AC | 90 ms | 54912 KB |
w4.txt | AC | 88 ms | 54016 KB |
w5.txt | AC | 105 ms | 58752 KB |
w6.txt | AC | 99 ms | 57600 KB |
w7.txt | AC | 105 ms | 52864 KB |
w8.txt | AC | 102 ms | 54912 KB |
w9.txt | AC | 108 ms | 58624 KB |