답안 #406138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
406138 2021-05-17T08:45:56 Z zaneyu From Hacks to Snitches (BOI21_watchmen) C++14
5 / 100
1331 ms 54728 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=15e6+5;
int dist[maxn];
int arr[125];
vector<int> v[100005];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    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,n*l) dist[i]=INF;
    queue<int> q;
    q.push(0);
    dist[0]=0;
    while(!q.empty()){
        int z=q.front();
        q.pop();
        int i=z%l,j=z/l;
        if(arr[(i+1)%l]!=j){
            int asd=j*l+(i+1)%l;
            if(dist[asd]>dist[z]+1){
                dist[asd]=dist[z]+1;
                q.push(asd);
            }
        }
        for(auto x:v[j]){
            if(x!=arr[(i+1)%l] and !(j==arr[(i+1)%l] and x==arr[i%l])){
                int asd=x*l+(i+1)%l;
                if(dist[asd]>dist[z]+1){
                    dist[asd]=dist[z]+1;
                    q.push(asd);
                }
            }
        }
        
    }
    int ans=INF;
    REP(i,l) MNTO(ans,dist[(n-1)*l+i]);
    if(ans==INF) cout<<"impossible";
    else cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 3788 KB Output is correct
2 Correct 613 ms 54728 KB Output is correct
3 Correct 944 ms 49648 KB Output is correct
4 Correct 1326 ms 49848 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 1049 ms 49672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 3788 KB Output is correct
2 Correct 613 ms 54708 KB Output is correct
3 Correct 838 ms 49656 KB Output is correct
4 Correct 1331 ms 49884 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 977 ms 49780 KB Output is correct
7 Incorrect 344 ms 26300 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 3788 KB Output is correct
2 Correct 613 ms 54708 KB Output is correct
3 Correct 838 ms 49656 KB Output is correct
4 Correct 1331 ms 49884 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 977 ms 49780 KB Output is correct
7 Incorrect 344 ms 26300 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 3788 KB Output is correct
2 Correct 613 ms 54708 KB Output is correct
3 Correct 838 ms 49656 KB Output is correct
4 Correct 1331 ms 49884 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 977 ms 49780 KB Output is correct
7 Incorrect 344 ms 26300 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 3788 KB Output is correct
2 Correct 613 ms 54728 KB Output is correct
3 Correct 944 ms 49648 KB Output is correct
4 Correct 1326 ms 49848 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 1049 ms 49672 KB Output is correct
7 Correct 126 ms 3788 KB Output is correct
8 Correct 613 ms 54708 KB Output is correct
9 Correct 838 ms 49656 KB Output is correct
10 Correct 1331 ms 49884 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 977 ms 49780 KB Output is correct
13 Incorrect 344 ms 26300 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 3788 KB Output is correct
2 Correct 613 ms 54728 KB Output is correct
3 Correct 944 ms 49648 KB Output is correct
4 Correct 1326 ms 49848 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 1049 ms 49672 KB Output is correct
7 Correct 126 ms 3788 KB Output is correct
8 Correct 613 ms 54708 KB Output is correct
9 Correct 838 ms 49656 KB Output is correct
10 Correct 1331 ms 49884 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 977 ms 49780 KB Output is correct
13 Incorrect 344 ms 26300 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 3788 KB Output is correct
2 Correct 613 ms 54728 KB Output is correct
3 Correct 944 ms 49648 KB Output is correct
4 Correct 1326 ms 49848 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 1049 ms 49672 KB Output is correct
7 Correct 126 ms 3788 KB Output is correct
8 Correct 613 ms 54708 KB Output is correct
9 Correct 838 ms 49656 KB Output is correct
10 Correct 1331 ms 49884 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 977 ms 49780 KB Output is correct
13 Incorrect 344 ms 26300 KB Output isn't correct
14 Halted 0 ms 0 KB -