이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll long long int
#define oo 1e18 + 5
#define pii pair<int, int>
const int MAX = 1005;
bitset<MAX> visited;
set<int> g[MAX];
bitset<MAX> accesible[MAX];
void dfs(int node, int par){
visited[node] = true;
accesible[par][node] = true;
accesible[node][par] = true;
for(int to : g[node]){
if(!visited[to]){
if(to < par){
accesible[par] |= accesible[to];
visited |= accesible[to];
continue;
}
dfs(to, par);
}
}
}
int main(){
int n, m, q; cin >> n >> m >> q;
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= n; j++)
{
int a; cin >> a;
if(a == j) continue;
g[j].insert(a);
g[a].insert(j);
}
}
for (int i = 1; i <= n; i++)
{
dfs(i, i);
visited.reset();
}
while(q--){
int a, b; cin >> a >> b;
if(accesible[a][b]){
cout << "DA\n";
}
else{
cout << "NE\n";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |