답안 #558439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558439 2022-05-07T10:17:29 Z Yazan_Alattar Tenis (COI19_tenis) C++14
0 / 100
77 ms 25044 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define aint(x) x.begin(), x.end()
const int M = 100007;
const ll inf = 2e9;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-6;
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;

stack <int> st;
vector <int> adj[M], revadj[M];
int n, q, a[5][M], in[M],comp[M], comps;
bool vist[M];

void dfs(int node){
    vist[node] = 1;
    for(auto i : adj[node]) if(!vist[i]) dfs(i);

    st.push(node);
    return;
}

void revdfs(int node){
    vist[node] = 1;
    comp[node] = comps;

    for(auto i : revadj[node]) if(!vist[i]) revdfs(i);
    return;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    for(int i = 1; i <= 3; ++i){
        for(int j = 1; j <= n; ++j){
            cin >> a[i][j];

            if(j > 1){
                adj[a[i][j - 1]].pb(a[i][j]);
                revadj[a[i][j]].pb(a[i][j - 1]);
            }
        }
    }

//    for(int i = 1; i <= n; ++i) if(!vist[i]) dfs(i);
//    for(int i = 1; i <= n; ++i) vist[i] = 0;
//
//    while(st.size()){
//        int node = st.top();
//        st.pop();
//        if(vist[node]) continue;
//
//        ++comps;
//        revdfs(node);
//    }
//
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j < n; ++j){
            int x = comp[a[i][j]], y = comp[a[i][j + 1]];
            if(x != y) ++in[y];
        }
    }

    while(q--){
        int type;
        cin >> type;

        if(type == 1){
            int x;
            cin >> x;

            if(!in[comp[x]]) cout << "DA\n";
            else cout << "NE\n";
        }

        else{
            int x, y, z;
            cin >> x >> y >> z;
        }
    }
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 9940 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 9940 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 9940 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 77 ms 25044 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 9940 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -