Submission #32851482
Source Code Expand
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
#define re register
#define fep(i,l,r) for(re int i=l;i<=r;++i)
#define feb(i,r,l) for(re int i=r;i>=l;--i)
#define For(i,u) for(re int i=head[u];i;i=e[i].nxt)
#define int long long
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 3e5+5;
int n,head[N],tot,m,INF;
struct Egde
{
int v,nxt;
}e[N<<1];
struct SPFA
{
int dis[N]; bool vis[N];
inline void spfa(int s)
{
queue<int> q; fep(i,1,n) dis[i]=INF,vis[i]=false;
dis[s]=0; vis[s]=true; q.push(s);// cout<<dis[2]<<endl;
while(!q.empty())
{
int u=q.front(); q.pop(); vis[u]=false;
For(i,u) if(dis[e[i].v]>dis[u]+1)
{
dis[e[i].v]=dis[u]+1;
if(!vis[e[i].v]) q.push(e[i].v),vis[e[i].v]=true;
}
}
}
}a[5];
inline int read() { int s=0,w=1; char ch=getchar(); while(!(ch<='9'&&ch>='0')) {if(ch=='-') w=-1; ch=getchar();} while(ch<='9'&&ch>='0') {s=(s<<1)+(s<<3)+(ch^48); ch=getchar();} return s*w; }
inline void write(int x) { if(x>=10) write(x/10); putchar(x%10+'0'); }
inline void print(int x,char ch) { if(x<0) putchar('-'),x=~(x-1); write(x); putchar(ch);}
inline void swap(int &x,int &y) {x^=y; y^=x; x^=y;}
inline void add(int u,int v) {e[++tot]={v,head[u]}; head[u]=tot;}
signed main()
{
n=read(),m=read(); INF=1e9; vector<int > unknow; int cnt=0;
fep(i,1,m)
{
int u=read(),v=read();
if(u==0) unknow.emplace_back(v),cnt+=(v==1)+(v==n);
else if(v==0) unknow.emplace_back(u),cnt+=(u==1)+(u==n);
else add(u,v),add(v,u);
}
a[1].spfa(1); a[2].spfa(n);
int ans1=INF,ans2=INF;
fep(j,0,(int)unknow.size()-1)
ans1=min(ans1,a[2].dis[unknow[j]]+1),
ans2=min(ans2,a[1].dis[unknow[j]]+1);
fep(i,1,n)
{
int res=a[1].dis[n]; if(cnt==2) res=min(res,2ll);
res=min(res,min(ans1+a[1].dis[i],ans2+a[2].dis[i]));
print(res>=INF?-1:res,' ');
}
return 0;
}
Submission Info
Submission Time
2022-06-30 20:59:30+0900
Task
F - Teleporter Setting
User
lasky
Language
C++ (GCC 9.2.1)
Score
500
Code Size
1953 Byte
Status
AC
Exec Time
83 ms
Memory
22444 KiB
Compile Error
./Main.cpp: In member function ‘void SPFA::spfa(long long int)’:
./Main.cpp:24:21: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
24 | queue<int> q; fep(i,1,n) dis[i]=INF,vis[i]=false;
| ^
./Main.cpp:5:31: note: in definition of macro ‘fep’
5 | #define fep(i,l,r) for(re int i=l;i<=r;++i)
| ^
./Main.cpp:29:8: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
29 | For(i,u) if(dis[e[i].v]>dis[u]+1)
| ^
./Main.cpp:7:29: note: in definition of macro ‘For’
7 | #define For(i,u) for(re int i=head[u];i;i=e[i].nxt)
| ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:47:6: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
47 | fep(i,1,m)
| ^
./Main.cpp:5:31: note: in definition of macro ‘fep’
5 | #define fep(i,l,r) for(re int i=l;i<=r;++i)
| ^
./Main.cpp:56:6: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
56 | fep(j,0,(int)unknow.size()-1)
| ^
./Main.cpp:5:31: note: in definition of macro ‘fep’
5 | #define fep(i,l,r) for(re int i=l;i<=r;++i)
| ^
./Main.cpp:59:6: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
59 | fep(i,1,n)
| ^
./Main.cpp:5:31: note: in definition of macro ‘fep’
5 | #define fep(i,l,r) for(re int i=l;i<=r;++i)
| ^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
500 / 500
Status
Set Name
Test Cases
Sample
example_00.txt, example_01.txt
All
example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, hand_18.txt, hand_19.txt, hand_20.txt, hand_21.txt, hand_22.txt, hand_23.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt
Case Name
Status
Exec Time
Memory
example_00.txt
AC
7 ms
3584 KiB
example_01.txt
AC
2 ms
3644 KiB
hand_00.txt
AC
41 ms
20416 KiB
hand_01.txt
AC
43 ms
20404 KiB
hand_02.txt
AC
45 ms
20540 KiB
hand_03.txt
AC
44 ms
20584 KiB
hand_04.txt
AC
44 ms
20540 KiB
hand_05.txt
AC
42 ms
20620 KiB
hand_06.txt
AC
45 ms
20556 KiB
hand_07.txt
AC
42 ms
20536 KiB
hand_08.txt
AC
64 ms
20640 KiB
hand_09.txt
AC
66 ms
20608 KiB
hand_10.txt
AC
59 ms
20580 KiB
hand_11.txt
AC
60 ms
20608 KiB
hand_12.txt
AC
69 ms
20444 KiB
hand_13.txt
AC
15 ms
8832 KiB
hand_14.txt
AC
30 ms
10832 KiB
hand_15.txt
AC
54 ms
20600 KiB
hand_16.txt
AC
83 ms
20784 KiB
hand_17.txt
AC
49 ms
16584 KiB
hand_18.txt
AC
50 ms
16736 KiB
hand_19.txt
AC
15 ms
8884 KiB
hand_20.txt
AC
14 ms
8708 KiB
hand_21.txt
AC
46 ms
22444 KiB
hand_22.txt
AC
39 ms
12928 KiB
hand_23.txt
AC
14 ms
8872 KiB
random_00.txt
AC
30 ms
12272 KiB
random_01.txt
AC
20 ms
6680 KiB
random_02.txt
AC
29 ms
12828 KiB
random_03.txt
AC
19 ms
10600 KiB
random_04.txt
AC
11 ms
4332 KiB
random_05.txt
AC
24 ms
11616 KiB
random_06.txt
AC
35 ms
10796 KiB
random_07.txt
AC
13 ms
4888 KiB
random_08.txt
AC
23 ms
14080 KiB
random_09.txt
AC
31 ms
12104 KiB
random_10.txt
AC
17 ms
6312 KiB
random_11.txt
AC
23 ms
14172 KiB
random_12.txt
AC
38 ms
11356 KiB
random_13.txt
AC
9 ms
4504 KiB
random_14.txt
AC
28 ms
11612 KiB
random_15.txt
AC
25 ms
10208 KiB
random_16.txt
AC
11 ms
4292 KiB
random_17.txt
AC
35 ms
15780 KiB
random_18.txt
AC
32 ms
10520 KiB
random_19.txt
AC
15 ms
6508 KiB
random_20.txt
AC
41 ms
13072 KiB