#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
vi adjList[200000];
int dist[200000];
queue<int> Q;
int main() {
int i;
int N,M;
int s,d,a,b,u,v;
scanf("%d %d",&N,&M);
scanf("%d %d %d %d",&s,&d,&a,&b);
s--,d--,a--,b--;
for (i = 0; i < M; i++) {
scanf("%d %d",&u,&v);
u--,v--;
adjList[u].pb(v);
adjList[v].pb(u);
}
fill(dist,dist+N,-1);
dist[a] = 0;
Q.push(a);
while (!Q.empty()) {
u = Q.front();
Q.pop();
for (i = 0; i < adjList[u].size(); i++) {
v = adjList[u][i];
if (dist[v] == -1) {
dist[v] = dist[u]+1;
Q.push(v);
}
}
}
int x = dist[d]-dist[s];
fill(dist,dist+N,-1);
dist[b] = 0;
Q.push(b);
while (!Q.empty()) {
u = Q.front();
Q.pop();
for (i = 0; i < adjList[u].size(); i++) {
v = adjList[u][i];
if (dist[v] == -1) {
dist[v] = dist[u]+1;
Q.push(v);
}
}
}
int y = dist[d]-dist[s];
printf("%d\n",max(min(x,y),-1));
return 0;
}
Compilation message
007.cpp: In function 'int main()':
007.cpp:82:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
007.cpp:98:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
007.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&N,&M);
~~~~~^~~~~~~~~~~~~~~
007.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d",&s,&d,&a,&b);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&u,&v);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
5156 KB |
Output is correct |
3 |
Correct |
6 ms |
5168 KB |
Output is correct |
4 |
Incorrect |
6 ms |
5168 KB |
Output isn't correct |
5 |
Incorrect |
6 ms |
5192 KB |
Output isn't correct |
6 |
Correct |
6 ms |
5236 KB |
Output is correct |
7 |
Correct |
6 ms |
5236 KB |
Output is correct |
8 |
Incorrect |
6 ms |
5236 KB |
Output isn't correct |
9 |
Correct |
6 ms |
5236 KB |
Output is correct |
10 |
Correct |
6 ms |
5236 KB |
Output is correct |
11 |
Correct |
6 ms |
5236 KB |
Output is correct |
12 |
Incorrect |
6 ms |
5236 KB |
Output isn't correct |
13 |
Correct |
6 ms |
5236 KB |
Output is correct |
14 |
Incorrect |
6 ms |
5236 KB |
Output isn't correct |
15 |
Correct |
6 ms |
5236 KB |
Output is correct |
16 |
Incorrect |
6 ms |
5236 KB |
Output isn't correct |
17 |
Incorrect |
6 ms |
5236 KB |
Output isn't correct |
18 |
Incorrect |
8 ms |
5344 KB |
Output isn't correct |
19 |
Correct |
6 ms |
5408 KB |
Output is correct |
20 |
Correct |
6 ms |
5444 KB |
Output is correct |
21 |
Correct |
8 ms |
5444 KB |
Output is correct |
22 |
Correct |
8 ms |
5444 KB |
Output is correct |
23 |
Correct |
6 ms |
5444 KB |
Output is correct |
24 |
Incorrect |
6 ms |
5508 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
7300 KB |
Output is correct |
2 |
Incorrect |
33 ms |
8292 KB |
Output isn't correct |
3 |
Correct |
29 ms |
8292 KB |
Output is correct |
4 |
Incorrect |
36 ms |
8352 KB |
Output isn't correct |
5 |
Correct |
28 ms |
8352 KB |
Output is correct |
6 |
Correct |
48 ms |
8352 KB |
Output is correct |
7 |
Correct |
30 ms |
8352 KB |
Output is correct |
8 |
Correct |
32 ms |
8352 KB |
Output is correct |
9 |
Incorrect |
46 ms |
8352 KB |
Output isn't correct |
10 |
Correct |
178 ms |
12692 KB |
Output is correct |
11 |
Incorrect |
54 ms |
12692 KB |
Output isn't correct |
12 |
Correct |
77 ms |
12692 KB |
Output is correct |
13 |
Incorrect |
65 ms |
12692 KB |
Output isn't correct |
14 |
Correct |
56 ms |
12692 KB |
Output is correct |
15 |
Correct |
79 ms |
12692 KB |
Output is correct |
16 |
Correct |
88 ms |
12692 KB |
Output is correct |
17 |
Correct |
75 ms |
12692 KB |
Output is correct |
18 |
Incorrect |
74 ms |
12692 KB |
Output isn't correct |
19 |
Correct |
124 ms |
12692 KB |
Output is correct |
20 |
Incorrect |
252 ms |
14056 KB |
Output isn't correct |
21 |
Incorrect |
113 ms |
14056 KB |
Output isn't correct |
22 |
Correct |
138 ms |
14056 KB |
Output is correct |
23 |
Correct |
117 ms |
14056 KB |
Output is correct |
24 |
Correct |
117 ms |
14056 KB |
Output is correct |
25 |
Incorrect |
117 ms |
14056 KB |
Output isn't correct |
26 |
Correct |
108 ms |
14056 KB |
Output is correct |
27 |
Correct |
125 ms |
14056 KB |
Output is correct |
28 |
Correct |
144 ms |
14056 KB |
Output is correct |
29 |
Correct |
168 ms |
14056 KB |
Output is correct |
30 |
Incorrect |
286 ms |
14624 KB |
Output isn't correct |
31 |
Incorrect |
125 ms |
14624 KB |
Output isn't correct |
32 |
Correct |
126 ms |
14624 KB |
Output is correct |
33 |
Correct |
122 ms |
14624 KB |
Output is correct |
34 |
Incorrect |
114 ms |
14624 KB |
Output isn't correct |
35 |
Incorrect |
101 ms |
14624 KB |
Output isn't correct |
36 |
Incorrect |
116 ms |
14624 KB |
Output isn't correct |
37 |
Correct |
130 ms |
14624 KB |
Output is correct |
38 |
Correct |
117 ms |
14624 KB |
Output is correct |
39 |
Correct |
155 ms |
14624 KB |
Output is correct |
40 |
Incorrect |
214 ms |
14624 KB |
Output isn't correct |
41 |
Correct |
323 ms |
16812 KB |
Output is correct |