답안 #748168

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748168 2023-05-25T13:36:14 Z vjudge1 From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
939 ms 133888 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=250000+10;
vector<int>adj[maxn],allk[maxn];
int n,m,k,dp[130][maxn],inf=1e8+5,ki;
vector<int>bf;

int bad(int i){
    i++;
    i%=ki;
    return i;
}

void solve(int len=0){
    if(bf.size()==0){
        return ;
    }
    for(auto x:bf){
        dp[len%ki][x]=len;
    }
    vector<int>fake;
    for(auto x:bf){
        for(auto y:adj[x]){
            if(dp[bad(len)][y]==inf&&allk[1][bad(len)]!=y&&!(allk[1][len%k]==y&&allk[1][bad(len)]==x)){
                fake.push_back(y);
                dp[bad(len)][y]=len+1;
            }
        }
    }
    swap(bf,fake);
    return solve(len+1);
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<130;i++){
        for(int j=0;j<=n;j++){
            dp[i][j]=inf;
        }
    }
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=1;i<=n;i++){
        adj[i].push_back(i);
    }
    cin>>k;
    for(int i=1;i<=k;i++){
        cin>>ki;
        allk[i].resize(ki);
        for(int j=0;j<ki;j++){
            cin>>allk[i][j];
        }
    }
    bf.push_back(1);
    solve();
    int res=inf;
    for(int i=0;i<ki;i++){
        res=min(res,dp[i][n]);
    }
    cout<<res<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 14156 KB Output is correct
2 Incorrect 939 ms 133888 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 14184 KB Output is correct
2 Incorrect 913 ms 133580 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 14184 KB Output is correct
2 Incorrect 913 ms 133580 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 14184 KB Output is correct
2 Incorrect 913 ms 133580 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 14156 KB Output is correct
2 Incorrect 939 ms 133888 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 14156 KB Output is correct
2 Incorrect 939 ms 133888 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 14156 KB Output is correct
2 Incorrect 939 ms 133888 KB Output isn't correct
3 Halted 0 ms 0 KB -