This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <iostream>
# include <iomanip>
# include <algorithm>
# include <cmath>
# include <queue>
# include <map>
# include <set>
# include <cstring>
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define pii pair <int, int>
# define pll pair <ll, ll>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll maxn = 1e3 + 25;
const ll maxl = 20 + 0;
const ll inf = 2e9 + 0;
const ll mod = 998244353;
using namespace std;
int n, m, q;
int p[maxn][maxn];
bool ok[maxn][maxn];
vector <ll> g[maxn];
vector <ll> gr[maxn];
bool used[maxn];
vector <ll > order;
ll comp[maxn];
void dfs1 (ll v)
{
used[v] = 1;
for (ll to : g[v])
{
if (!used[to])
{
dfs1(to);
}
}
order.pb(v);
}
void dfs2 (ll v, ll cl)
{
used[v] = 1;
comp[v] = cl;
for (ll to : gr[v])
{
if (!used[to])
{
dfs2(to, cl);
}
}
}
void ma1n ()
{
cin >> n >> m >> q;
for (int i = 1; i <= m; ++i)
{
for (int j = 1; j <= n; ++j)
{
cin >> p[i][j];
g[j].pb(p[i][j]);
gr[p[i][j]].pb(j);
}
}
for (ll v = 1; v <= n; ++v)
{
if (!used[v])
{
dfs1(v);
}
}
reverse(order.begin(), order.end());
ll cl = 1;
memset(used, 0, sizeof(used));
for (ll v : order)
{
if (!used[v])
{
dfs2(v, cl++);
}
}
while (q--)
{
ll a, b;
cin >> a >> b;
if (comp[a] == comp[b])
{
cout << "DA" << nl;
}
else
{
cout << "NE" << nl;
}
}
}
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int ttt = 1;
// cin >> ttt;
for (int test = 1; test <= ttt; test++)
{
// cout << "Case " << test << ":" << nl;
ma1n();
}
return 0;
}
# | 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... |