제출 #558440

#제출 시각아이디문제언어결과실행 시간메모리
558440Yazan_AlattarTenis (COI19_tenis)C++14
0 / 100
155 ms14808 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...