# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1237199 | alexandros | Kutije (COCI21_kutije) | C++20 | 121 ms | 10020 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> group;
vector<vector<ll>> connections;
void dfs(ll j, ll g)
{
group[j] = g;
for(ll i = 0; i < connections[j].size(); i++)
{
if(group[connections[j][i]] == -1) dfs(connections[j][i], g);
}
}
int main() {
ll amount, amountf, amountq, temp, cur = 0, start, end;
scanf("%lld %lld %lld", &amount, &amountf, &amountq);
group.assign(amount, -1);
connections.assign(amount, vector<ll>());
for(ll i = 0; i < amountf; i++)
{
for(ll j = 0; j < amount; j++)
{
scanf("%lld", &temp);
connections[j].push_back(temp-1);
}
}
for(ll i = 0; i < amount; i++)
{
if(group[i] == -1)
{
dfs(i, cur);
cur++;
}
}
for(ll i = 0; i < amountq; i++)
{
scanf("%lld %lld", &start, &end);
if(group[start-1] == group[end-1]) printf("DA\n");
else printf("NE\n");
}
}
Compilation message (stderr)
# | 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... |