# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
405203 | CaroLinda | From Hacks to Snitches (BOI21_watchmen) | C++14 | 936 ms | 524292 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
const int MAX = 12599999 ;
#define pb push_back
#define mk make_pair
using namespace std ;
int N , M , K ,C ;
int dist[ MAX ] ;
vector<pair<int,int> > edge ;
vector<int> adj[ MAX ] ;
bool nao_pode[MAX] ;
int fila[MAX] ;
int code(int x, int y) { return (x-1)+y*100000 ; }
void bfs()
{
int ini = 0 , fim =1 ;
fila[0] = code(1,0) ;
for(int i = 0 ; i < MAX ; i++ ) dist[i] = -1 ;
dist[ code(1,0) ] = 0;
while(ini < fim)
{
int x = fila[ini++] ;
for(auto e : adj[x] )
{
if( dist[e] != -1 ) continue ;
if( nao_pode[e] ) continue ;
dist[e] = dist[x]+1 ;
fila[fim++] = e ;
}
}
}
int main()
{
scanf("%d %d", &N, &M ) ;
for(int i = 1 , u , v ; i<= M ; i++ )
{
scanf("%d %d", &u, &v ) ;
edge.pb(mk(u,v)) ;
}
scanf("%d", &K ) ;
scanf("%d", &C ) ;
for(int i = 1 ; i <= N ; i++ )
for(int j = 0 ; j < C ; j++ )
adj[ code(i,j) ].pb( code(i,(j+1)%C) ) ;
for(int i = 0 , x ; i < C ; i++ )
{
scanf("%d", &x ) ;
nao_pode[ code(x,i) ] = true ;
}
for(auto &e : edge )
for(int g = 0 ; g < 2 ; g++ , swap(get<0>(e) , get<1>(e)))
for(int i = 0 ; i < C ; i++ )
{
if( nao_pode[ code(get<1>(e),i) ] && nao_pode[ code(get<0>(e),(i+1)%C) ] ) continue ;
adj[ code(get<0>(e),i) ].pb( code(get<1>(e),(i+1)%C ) ) ;
}
bfs() ;
int ans = -1 ;
for(int i = 0 ; i < C ; i++ )
{
int p = code(N,i) ;
if(dist[p] == -1) continue ;
if(ans == -1 || dist[p] < ans ) ans = dist[p] ;
}
if( ans == -1 ) { printf("impossible\n") ; return 0 ; }
printf("%d\n" , ans ) ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |