Submission #3229439


Source Code Expand

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <unordered_map>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

int N,M;
vector<int> out[100500], in[100500];
int from[500500], to[500500], c[500500];
int dist[500500];
int main(){
	scanf("%d%d",&N,&M);
	for(int i=1;i<=M;i++){
		int x,y,z; scanf("%d%d%d",&x,&y,&z);
		from[i*2-1] = x; to[i*2-1] = y; c[i*2-1] = z;
		from[i*2] = y; to[i*2] = x; c[i*2] = z;
		out[x].push_back(i*2-1); in[y].push_back(i*2-1);
		out[y].push_back(i*2); in[x].push_back(i*2);
	}
	for(int i=1;i<=M*2;i++) dist[i] = 1e9;
	priority_queue<pii, vector<pii>, greater<pii>> pq;
	for(auto e : out[1]){
		dist[e] = 1;
		pq.push({1,e});
	}

	while( !pq.empty() ){
		int cur = pq.top().Se,  curd = pq.top().Fi;
		pq.pop();
		if( curd != dist[cur] ) continue;

		int x = from[cur], y = to[cur], z = c[cur];
		for(auto e : out[y]){
			int t = 1;
			if( c[e] == z ) t = 0;
			if( dist[e] > curd + t ){
				dist[e] = curd + t;
				pq.push({dist[e],e});
			}
		}
	}


	int ans = 1e9;
	for(auto e : in[N]){
		ans = min(ans, dist[e]);
	}
	if( ans >= 1e8 ) printf("-1\n");
	else printf("%d\n",ans);
}











Submission Info

Submission Time
Task E - Snuke's Subway Trip
User kjp4155
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1671 Byte
Status TLE
Exec Time 3160 ms
Memory 26480 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:36:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&N,&M);
                     ^
./Main.cpp:38:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   int x,y,z; scanf("%d%d%d",&x,&y,&z);
                                      ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status AC
AC × 29
TLE × 30
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 4 ms 10752 KB
02.txt AC 791 ms 21876 KB
03.txt AC 219 ms 22904 KB
04.txt AC 101 ms 20736 KB
05.txt AC 204 ms 22904 KB
06.txt AC 55 ms 17920 KB
07.txt AC 84 ms 18176 KB
08.txt AC 190 ms 22136 KB
09.txt AC 86 ms 18176 KB
10.txt AC 91 ms 18176 KB
11.txt TLE 3156 ms 25348 KB
12.txt TLE 3156 ms 25576 KB
13.txt TLE 3156 ms 21872 KB
14.txt AC 581 ms 21752 KB
15.txt TLE 3156 ms 20728 KB
16.txt AC 2153 ms 21912 KB
17.txt TLE 3160 ms 21872 KB
18.txt TLE 3156 ms 23024 KB
19.txt TLE 3156 ms 21804 KB
20.txt AC 1181 ms 24324 KB
21.txt TLE 3156 ms 22896 KB
22.txt TLE 3156 ms 22260 KB
23.txt AC 198 ms 22004 KB
24.txt TLE 3156 ms 21768 KB
25.txt TLE 3156 ms 22508 KB
26.txt TLE 3156 ms 23020 KB
27.txt AC 572 ms 21752 KB
28.txt TLE 3156 ms 21816 KB
29.txt AC 2141 ms 23532 KB
30.txt TLE 3156 ms 22892 KB
31.txt TLE 3156 ms 22132 KB
32.txt TLE 3156 ms 21804 KB
33.txt AC 1180 ms 22024 KB
34.txt TLE 3156 ms 21768 KB
35.txt TLE 3156 ms 21236 KB
36.txt TLE 3156 ms 22892 KB
37.txt AC 584 ms 21752 KB
38.txt TLE 3156 ms 21816 KB
sample_01.txt AC 4 ms 10752 KB
sample_02.txt AC 4 ms 10752 KB
sample_03.txt AC 3 ms 6656 KB
w1.txt TLE 3156 ms 24032 KB
w10.txt AC 98 ms 18048 KB
w11.txt TLE 3156 ms 26480 KB
w12.txt AC 2997 ms 26220 KB
w13.txt AC 282 ms 16896 KB
w14.txt AC 116 ms 18048 KB
w15.txt TLE 3156 ms 25068 KB
w16.txt TLE 3010 ms 25472 KB
w17.txt AC 449 ms 25708 KB
w18.txt AC 144 ms 18048 KB
w2.txt TLE 3156 ms 25036 KB
w3.txt TLE 3156 ms 22892 KB
w4.txt TLE 3156 ms 22888 KB
w5.txt TLE 3156 ms 23912 KB
w6.txt TLE 3156 ms 23916 KB
w7.txt TLE 3156 ms 19576 KB
w8.txt AC 2698 ms 16384 KB
w9.txt AC 236 ms 16896 KB