# 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 |
1 |
Correct |
83 ms |
5708 KB |
Output is correct |
2 |
Correct |
80 ms |
5060 KB |
Output is correct |
3 |
Correct |
81 ms |
4696 KB |
Output is correct |
4 |
Correct |
85 ms |
5756 KB |
Output is correct |
5 |
Correct |
124 ms |
5672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1032 KB |
Output is correct |
2 |
Correct |
2 ms |
1032 KB |
Output is correct |
3 |
Correct |
1 ms |
904 KB |
Output is correct |
4 |
Correct |
1 ms |
908 KB |
Output is correct |
5 |
Correct |
2 ms |
1004 KB |
Output is correct |
6 |
Correct |
1 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
1004 KB |
Output is correct |
8 |
Correct |
2 ms |
980 KB |
Output is correct |
9 |
Correct |
2 ms |
980 KB |
Output is correct |
10 |
Correct |
2 ms |
1000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1032 KB |
Output is correct |
2 |
Correct |
2 ms |
1032 KB |
Output is correct |
3 |
Correct |
1 ms |
904 KB |
Output is correct |
4 |
Correct |
1 ms |
908 KB |
Output is correct |
5 |
Correct |
2 ms |
1004 KB |
Output is correct |
6 |
Correct |
1 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
1004 KB |
Output is correct |
8 |
Correct |
2 ms |
980 KB |
Output is correct |
9 |
Correct |
2 ms |
980 KB |
Output is correct |
10 |
Correct |
2 ms |
1000 KB |
Output is correct |
11 |
Correct |
3 ms |
1036 KB |
Output is correct |
12 |
Correct |
2 ms |
1032 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
980 KB |
Output is correct |
15 |
Correct |
2 ms |
904 KB |
Output is correct |
16 |
Correct |
2 ms |
1032 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
2 ms |
980 KB |
Output is correct |
19 |
Correct |
2 ms |
980 KB |
Output is correct |
20 |
Correct |
3 ms |
1028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
5708 KB |
Output is correct |
2 |
Correct |
80 ms |
5060 KB |
Output is correct |
3 |
Correct |
81 ms |
4696 KB |
Output is correct |
4 |
Correct |
85 ms |
5756 KB |
Output is correct |
5 |
Correct |
124 ms |
5672 KB |
Output is correct |
6 |
Correct |
3 ms |
1032 KB |
Output is correct |
7 |
Correct |
2 ms |
1032 KB |
Output is correct |
8 |
Correct |
1 ms |
904 KB |
Output is correct |
9 |
Correct |
1 ms |
908 KB |
Output is correct |
10 |
Correct |
2 ms |
1004 KB |
Output is correct |
11 |
Correct |
1 ms |
1004 KB |
Output is correct |
12 |
Correct |
2 ms |
1004 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
14 |
Correct |
2 ms |
980 KB |
Output is correct |
15 |
Correct |
2 ms |
1000 KB |
Output is correct |
16 |
Correct |
3 ms |
1036 KB |
Output is correct |
17 |
Correct |
2 ms |
1032 KB |
Output is correct |
18 |
Correct |
2 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
2 ms |
904 KB |
Output is correct |
21 |
Correct |
2 ms |
1032 KB |
Output is correct |
22 |
Correct |
1 ms |
980 KB |
Output is correct |
23 |
Correct |
2 ms |
980 KB |
Output is correct |
24 |
Correct |
2 ms |
980 KB |
Output is correct |
25 |
Correct |
3 ms |
1028 KB |
Output is correct |
26 |
Correct |
192 ms |
30876 KB |
Output is correct |
27 |
Correct |
195 ms |
30924 KB |
Output is correct |
28 |
Correct |
163 ms |
27292 KB |
Output is correct |
29 |
Correct |
177 ms |
30156 KB |
Output is correct |
30 |
Correct |
162 ms |
26912 KB |
Output is correct |
31 |
Correct |
169 ms |
27752 KB |
Output is correct |
32 |
Correct |
183 ms |
29916 KB |
Output is correct |
33 |
Correct |
192 ms |
29572 KB |
Output is correct |
34 |
Correct |
178 ms |
29608 KB |
Output is correct |
35 |
Correct |
192 ms |
30784 KB |
Output is correct |