QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#719618#3601. On Average They're PurpleandaheTL 10ms9700kbC++20924b2024-11-07 05:11:562024-11-07 05:11:56

Judging History

This is the latest submission verdict.

  • [2024-11-07 05:11:56]
  • Judged
  • Verdict: TL
  • Time: 10ms
  • Memory: 9700kb
  • [2024-11-07 05:11:56]
  • Submitted

answer

#include<bits/stdc++.h> 
#define ll long long 
#define LL __int128_t 
#define PB push_back
#define MK make_pair
#define fi first
#define se second
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i <= _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i >= _##i; --i)
#define debug(x) cout<< "\033 -> "<<#x<<": "<<x<<endl
using namespace std;
const int N(100005);
vector<int> e[N];
int vis[N], dis[N];
int main() 
{ 
//	freopen("1.in","r",stdin); 
	ios::sync_with_stdio(false); 
	cin.tie(NULL);
	int n, m; cin >> n >> m;
	FOR(i, 1, m)
	{
		int x, y; cin >> x >> y;
		e[x].PB(y), e[y].PB(x);
	}
	queue<int> q; q.push(1); vis[1] = 1;
	while(!q.empty())
	{
		int x = q.front(); q.pop();
		if(x == n) break;
		for(auto &to : e[x]) if(!vis[to])
		{
			q.push(to);
			dis[to] = dis[x] + 1;
		}
	}
	cout<<dis[n]-1<<endl;
	return 0; 
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3832kb

input:

3 3
1 3
1 2
2 3

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

7 8
1 2
1 3
2 4
3 4
4 5
4 6
5 7
6 7

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 10ms
memory: 9700kb

input:

100000 99999
1 82839
79117 1
52850 1
1 98692
1 97570
1 52713
1 69481
86347 1
1 78467
32605 1
1 50497
32776 1
96243 1
1 63191
1 40685
6039 1
42700 1
36636 1
14590 1
89412 1
96386 1
1 67084
74195 1
79616 1
1 7286
1 85081
82925 1
31913 1
1 21516
32383 1
1 57458
12240 1
1 93520
1 34296
36228 1
1 75440
1...

output:

0

result:

ok single line: '0'

Test #4:

score: -100
Time Limit Exceeded

input:

100000 99999
27258 66566
49213 38165
7349 35601
47068 59589
82972 21228
78010 70856
22573 21068
82303 88214
70714 58816
56991 82670
85959 16532
78640 33897
24436 19989
65698 53247
26936 48520
98934 34959
8790 31287
14159 78214
57169 40287
76148 2201
86479 91453
5488 41694
74869 54823
89247 61215
519...

output:


result: