답안 #406128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
406128 2021-05-17T08:40:48 Z zaneyu From Hacks to Snitches (BOI21_watchmen) C++14
0 / 100
396 ms 524292 KB
/*input
6 6
1 2
2 3
3 4
4 5
5 2
5 6
1
4 4 5 2 3
*/


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//#pragma GCC optimize("O2","unroll-loops","no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x)(int)x.size()
#define SORT_UNIQUE(c)(sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
inline ll mult(ll a,ll b){
    if(a<0) a+=MOD;
    if(b<0) b+=MOD;
    if(a>=MOD) a%=MOD;
    if(b>=MOD) b%=MOD;
    return(a*b)%MOD;
}
inline ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const int maxn=2e7+5;
int dist[maxn];
int arr[125];
vector<int> v[100005];
vector<int> vv[maxn];
int main(){
    int n,m;
    cin>>n>>m;
    REP(i,m){
        int a,b;
        cin>>a>>b;
        --a;
        --b;
        v[a].pb(b);
        v[b].pb(a);
    }
    REP(i,n) dist[i]=INF;
    int k;
    cin>>k;
    int l;
    REP(i,k){
        cin>>l;
        REP(j,l) cin>>arr[j],--arr[j];
    }
    REP(i,l){
        REP(j,n){
            if(arr[(i+1)%l]!=j) vv[j*l+i].pb(j*l+(i+1)%l);
            for(auto x:v[j]){
                if(x!=arr[(i+1)%l] and !(j==arr[(i+1)%l] and x==arr[i%l])){
                    vv[j*l+i].pb(x*l+(i+1)%l);
                }
            }
        }
    }
    REP(i,n*l) dist[i]=INF;
    queue<int> q;
    q.push(0);
    dist[0]=0;
    while(!q.empty()){
        int z=q.front();
        q.pop();
        for(int x:vv[z]){
            if(dist[x]>dist[z]+1){
                dist[x]=dist[z]+1;
                q.push(x);
            }
        }
    }
    int ans=INF;
    REP(i,l) MNTO(ans,dist[(n-1)*l+i]);
    if(ans==INF) cout<<"impossible";
    else cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 396 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 346 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 346 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 346 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 396 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 396 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 396 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -