# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
171597 |
2019-12-29T10:33:14 Z |
MvC |
007 (CEOI14_007) |
C++11 |
|
329 ms |
17484 KB |
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int n,m,s[2],a[2],d[2][nmax],x,y,mn,i,j;
vector<int>g[nmax];
queue<pair<int,int> >q;
pair<int,int>p;
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n>>m;
cin>>s[0]>>s[1]>>a[0]>>a[1];
while(m--)
{
cin>>x>>y;
g[x].pb(y);
g[y].pb(x);
}
for(j=0;j<2;j++)
{
for(i=1;i<=n;i++)d[j][i]=inf;
q.push(mkp(s[j],0));
d[j][s[j]]=0;
while(!q.empty())
{
p=q.front();
q.pop();
for(i=0;i<(int)g[p.fr].size();i++)
{
x=g[p.fr][i];
if(d[j][x]!=inf)continue;
d[j][x]=p.sc+1;
q.push(mkp(x,d[j][x]));
}
}
}
mn=inf;
for(i=0;i<2;i++)
{
x=a[i];
mn=min(mn,d[1][x]-d[0][x]);
}
if(mn<-1)mn=-1;
if(mn!=-1 && d[0][a[0]]==d[0][a[1]] && d[1][a[0]]==d[1][a[1]])mn--;
cout<<mn<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4988 KB |
Output is correct |
2 |
Correct |
7 ms |
4984 KB |
Output is correct |
3 |
Partially correct |
6 ms |
5116 KB |
Partially correct |
4 |
Correct |
7 ms |
5112 KB |
Output is correct |
5 |
Correct |
7 ms |
5092 KB |
Output is correct |
6 |
Partially correct |
7 ms |
5112 KB |
Partially correct |
7 |
Partially correct |
7 ms |
5112 KB |
Partially correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Partially correct |
7 ms |
5116 KB |
Partially correct |
10 |
Correct |
7 ms |
5112 KB |
Output is correct |
11 |
Correct |
7 ms |
5112 KB |
Output is correct |
12 |
Correct |
7 ms |
5112 KB |
Output is correct |
13 |
Partially correct |
7 ms |
5112 KB |
Partially correct |
14 |
Correct |
7 ms |
5112 KB |
Output is correct |
15 |
Partially correct |
7 ms |
5112 KB |
Partially correct |
16 |
Correct |
7 ms |
5112 KB |
Output is correct |
17 |
Correct |
7 ms |
5112 KB |
Output is correct |
18 |
Correct |
7 ms |
5240 KB |
Output is correct |
19 |
Partially correct |
7 ms |
5112 KB |
Partially correct |
20 |
Partially correct |
7 ms |
5112 KB |
Partially correct |
21 |
Correct |
7 ms |
5112 KB |
Output is correct |
22 |
Partially correct |
7 ms |
5112 KB |
Partially correct |
23 |
Partially correct |
7 ms |
5112 KB |
Partially correct |
24 |
Correct |
7 ms |
5112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
30 ms |
6904 KB |
Partially correct |
2 |
Correct |
39 ms |
7544 KB |
Output is correct |
3 |
Partially correct |
31 ms |
7032 KB |
Partially correct |
4 |
Correct |
44 ms |
7672 KB |
Output is correct |
5 |
Correct |
29 ms |
6880 KB |
Output is correct |
6 |
Correct |
29 ms |
7032 KB |
Output is correct |
7 |
Partially correct |
33 ms |
7288 KB |
Partially correct |
8 |
Partially correct |
37 ms |
7160 KB |
Partially correct |
9 |
Correct |
48 ms |
7672 KB |
Output is correct |
10 |
Partially correct |
168 ms |
12156 KB |
Partially correct |
11 |
Correct |
70 ms |
8832 KB |
Output is correct |
12 |
Partially correct |
84 ms |
9948 KB |
Partially correct |
13 |
Correct |
68 ms |
9336 KB |
Output is correct |
14 |
Correct |
58 ms |
8696 KB |
Output is correct |
15 |
Partially correct |
83 ms |
9848 KB |
Partially correct |
16 |
Correct |
101 ms |
10232 KB |
Output is correct |
17 |
Partially correct |
85 ms |
9592 KB |
Partially correct |
18 |
Correct |
80 ms |
9592 KB |
Output is correct |
19 |
Partially correct |
118 ms |
11024 KB |
Partially correct |
20 |
Correct |
218 ms |
13916 KB |
Output is correct |
21 |
Correct |
139 ms |
12024 KB |
Output is correct |
22 |
Partially correct |
108 ms |
10872 KB |
Partially correct |
23 |
Correct |
133 ms |
11772 KB |
Output is correct |
24 |
Partially correct |
132 ms |
11640 KB |
Partially correct |
25 |
Correct |
126 ms |
11388 KB |
Output is correct |
26 |
Correct |
105 ms |
11004 KB |
Output is correct |
27 |
Partially correct |
136 ms |
11768 KB |
Partially correct |
28 |
Partially correct |
136 ms |
11896 KB |
Partially correct |
29 |
Partially correct |
165 ms |
12568 KB |
Partially correct |
30 |
Correct |
239 ms |
14464 KB |
Output is correct |
31 |
Correct |
156 ms |
13048 KB |
Output is correct |
32 |
Partially correct |
133 ms |
12016 KB |
Partially correct |
33 |
Correct |
130 ms |
12296 KB |
Output is correct |
34 |
Correct |
186 ms |
12796 KB |
Output is correct |
35 |
Correct |
127 ms |
12284 KB |
Output is correct |
36 |
Correct |
133 ms |
12568 KB |
Output is correct |
37 |
Correct |
163 ms |
13636 KB |
Output is correct |
38 |
Partially correct |
154 ms |
13324 KB |
Partially correct |
39 |
Partially correct |
170 ms |
13432 KB |
Partially correct |
40 |
Correct |
229 ms |
15044 KB |
Output is correct |
41 |
Partially correct |
329 ms |
17484 KB |
Partially correct |