Submission #851841

#TimeUsernameProblemLanguageResultExecution timeMemory
851841vjudge1Kutije (COCI21_kutije)C++17
0 / 70
227 ms20916 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast,O3,unroll-loops") #define int long long #define vi vector<int> #define vvi vector<vi> #define pii pair<int, int> #define vpi vector<pii> #define vvpi vector<vpi> #define vb vector<bool> #define vvb vector<vb> #define endl "\n" #define sp << " " << #define F(i, s, n) for(int i = s; i < n; i++) #define pb push_back #define fi first #define se second int inf = LLONG_MAX >> 3; vvi adj(1001); vb visited(1001, false); vi tout(1001); vector<set<int>> can(1001); int x, y; bool ans = false; int t = 0; void dfs(int node) { if(visited[node]) return; visited[node] = true; for(int nei: adj[node]) dfs(nei); tout[node] = t++; } void solve() { int n, m, q; cin >> n >> m >> q; F(i, 0, m) { F(j, 0, n) { int x; cin >> x; x--; adj[x].pb(j); } } F(i, 0, n) { can[i].insert(i); dfs(i); } vi ord(n); F(i, 0, n) ord[i] = i; sort(ord.begin(), ord.end(), [](int a, int b) {return tout[a] < tout[b];}); F(i, 0, n) { int cur = ord[i]; for(int nei: adj[cur]) { for(int go: can[nei]) can[cur].insert(go); } } F(i, 0, q) { int x, y; cin >> x >> y; x--, y--; if(can[x].count(y)) cout << "DA" << endl; else cout << "NE" << endl; } } void setIO() { ios::sync_with_stdio(0); cin.tie(0); #ifdef Local freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } signed main() { setIO(); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...