#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define pb push_back
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << " " << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T x, S ...y){cerr << x << ", ";_do(y...);}
#else
#define bug(...) 49
#endif
const int maxn=200005;
int n,m,a,b,c,d,dis1[maxn],dis2[maxn],dis3[maxn],dis4[maxn],maxx=-1,maxx2=-1,ans;
vector<int> adj[maxn];
queue<int> q;
bool vis[maxn];
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> n >> m >> a >> b >> c >> d;
a--,b--,c--,d--;
rep(m){
int u,v;
cin >> u >> v;
u--,v--;
adj[u].pb(v),adj[v].pb(u);
}
memset(vis,0,sizeof vis);
q.push(a);
vis[a]=1;
dis1[a]=0;
while(!q.empty()){
int u=q.front();
q.pop();
for(auto v: adj[u]){
if(vis[v]) continue;
q.push(v);
vis[v]=1;
dis1[v]=dis1[u]+1;
}
}
memset(vis,0,sizeof vis);
q.push(b);
vis[b]=1;
dis2[b]=0;
while(!q.empty()){
int u=q.front();
q.pop();
for(auto v: adj[u]){
if(vis[v]) continue;
q.push(v);
vis[v]=1;
dis2[v]=dis2[u]+1;
}
}
memset(vis,0,sizeof vis);
q.push(c);
vis[c]=1;
dis3[c]=0;
while(!q.empty()){
int u=q.front();
q.pop();
for(auto v: adj[u]){
if(vis[v]) continue;
q.push(v);
vis[v]=1;
dis3[v]=dis3[u]+1;
}
}
memset(vis,0,sizeof vis);
q.push(d);
vis[d]=1;
dis4[d]=0;
while(!q.empty()){
int u=q.front();
q.pop();
for(auto v: adj[u]){
if(vis[v]) continue;
q.push(v);
vis[v]=1;
dis4[v]=dis4[u]+1;
}
}
bug(dis1[c],dis1[d],dis2[c],dis2[d]);
if(dis2[c]==dis2[d]){
rep(n) if(dis3[i]==dis4[i]&&dis3[i]+dis2[i]==dis2[c]) maxx=max(maxx,dis2[i]);
bug(maxx);
}
if(dis1[c]==dis1[d]){
rep(n) if(dis3[i]==dis4[i]&&dis3[i]+dis1[i]==dis1[c]) maxx2=max(maxx2,dis1[i]);
bug(maxx2);
}
int x=dis2[c],y=dis2[d];
while(min(dis1[c],dis1[d])<min(x,y)){
if(x==y){
if(maxx){
x--,y--,maxx--;
}
else if(dis1[c]>=dis1[d]) x--;
else y--;
}
else x--,y--;
ans++;
}
if(x<dis1[c]||y<dis1[d]){
cout << ans-1 << "\n";
return 0;
}
if(dis1[c]==dis1[d]){
if(x!=y) cout << ans << "\n";
else{
if(maxx>maxx2) cout << ans-1 << "\n";
else cout << ans << "\n";
}
return 0;
}
cout << ans << "\n";
}
Compilation message
007.cpp: In function 'int main()':
007.cpp:22:18: warning: statement has no effect [-Wunused-value]
22 | #define bug(...) 49
| ^~
007.cpp:101:5: note: in expansion of macro 'bug'
101 | bug(dis1[c],dis1[d],dis2[c],dis2[d]);
| ^~~
007.cpp:22:18: warning: statement has no effect [-Wunused-value]
22 | #define bug(...) 49
| ^~
007.cpp:104:9: note: in expansion of macro 'bug'
104 | bug(maxx);
| ^~~
007.cpp:22:18: warning: statement has no effect [-Wunused-value]
22 | #define bug(...) 49
| ^~
007.cpp:109:9: note: in expansion of macro 'bug'
109 | bug(maxx2);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5196 KB |
Output is correct |
2 |
Correct |
4 ms |
5196 KB |
Output is correct |
3 |
Correct |
4 ms |
5196 KB |
Output is correct |
4 |
Correct |
4 ms |
5148 KB |
Output is correct |
5 |
Correct |
4 ms |
5160 KB |
Output is correct |
6 |
Correct |
3 ms |
5196 KB |
Output is correct |
7 |
Correct |
3 ms |
5164 KB |
Output is correct |
8 |
Correct |
4 ms |
5196 KB |
Output is correct |
9 |
Correct |
4 ms |
5196 KB |
Output is correct |
10 |
Correct |
4 ms |
5156 KB |
Output is correct |
11 |
Correct |
3 ms |
5168 KB |
Output is correct |
12 |
Correct |
4 ms |
5164 KB |
Output is correct |
13 |
Correct |
4 ms |
5196 KB |
Output is correct |
14 |
Correct |
3 ms |
5196 KB |
Output is correct |
15 |
Correct |
4 ms |
5160 KB |
Output is correct |
16 |
Correct |
3 ms |
5196 KB |
Output is correct |
17 |
Correct |
5 ms |
5196 KB |
Output is correct |
18 |
Correct |
4 ms |
5196 KB |
Output is correct |
19 |
Correct |
4 ms |
5196 KB |
Output is correct |
20 |
Correct |
4 ms |
5292 KB |
Output is correct |
21 |
Correct |
3 ms |
5196 KB |
Output is correct |
22 |
Correct |
4 ms |
5196 KB |
Output is correct |
23 |
Correct |
4 ms |
5196 KB |
Output is correct |
24 |
Correct |
6 ms |
5308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
8344 KB |
Output is correct |
2 |
Correct |
35 ms |
9516 KB |
Output is correct |
3 |
Correct |
41 ms |
8420 KB |
Output is correct |
4 |
Correct |
45 ms |
9776 KB |
Output is correct |
5 |
Correct |
37 ms |
8264 KB |
Output is correct |
6 |
Correct |
27 ms |
8456 KB |
Output is correct |
7 |
Correct |
36 ms |
8876 KB |
Output is correct |
8 |
Correct |
32 ms |
8940 KB |
Output is correct |
9 |
Correct |
50 ms |
10408 KB |
Output is correct |
10 |
Correct |
188 ms |
23464 KB |
Output is correct |
11 |
Correct |
74 ms |
11972 KB |
Output is correct |
12 |
Correct |
98 ms |
14016 KB |
Output is correct |
13 |
Correct |
86 ms |
12644 KB |
Output is correct |
14 |
Correct |
70 ms |
11388 KB |
Output is correct |
15 |
Correct |
97 ms |
13924 KB |
Output is correct |
16 |
Correct |
112 ms |
14404 KB |
Output is correct |
17 |
Correct |
94 ms |
13292 KB |
Output is correct |
18 |
Correct |
83 ms |
13388 KB |
Output is correct |
19 |
Correct |
125 ms |
17428 KB |
Output is correct |
20 |
Correct |
221 ms |
26576 KB |
Output is correct |
21 |
Correct |
137 ms |
17212 KB |
Output is correct |
22 |
Correct |
123 ms |
15732 KB |
Output is correct |
23 |
Correct |
136 ms |
17068 KB |
Output is correct |
24 |
Correct |
151 ms |
16956 KB |
Output is correct |
25 |
Correct |
109 ms |
16380 KB |
Output is correct |
26 |
Correct |
114 ms |
15712 KB |
Output is correct |
27 |
Correct |
144 ms |
17160 KB |
Output is correct |
28 |
Correct |
157 ms |
17304 KB |
Output is correct |
29 |
Correct |
180 ms |
21044 KB |
Output is correct |
30 |
Correct |
267 ms |
28024 KB |
Output is correct |
31 |
Correct |
171 ms |
19048 KB |
Output is correct |
32 |
Correct |
148 ms |
17360 KB |
Output is correct |
33 |
Correct |
150 ms |
17596 KB |
Output is correct |
34 |
Correct |
173 ms |
18272 KB |
Output is correct |
35 |
Correct |
143 ms |
17560 KB |
Output is correct |
36 |
Correct |
150 ms |
18068 KB |
Output is correct |
37 |
Correct |
182 ms |
19812 KB |
Output is correct |
38 |
Correct |
179 ms |
19504 KB |
Output is correct |
39 |
Correct |
183 ms |
19588 KB |
Output is correct |
40 |
Correct |
251 ms |
25920 KB |
Output is correct |
41 |
Correct |
324 ms |
33604 KB |
Output is correct |