# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
718641 | filipmihov | Mostovi (COI14_mostovi) | C++98 | 14 ms | 11552 KiB |
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 <bits/stdc++.h>
using namespace std;
bool l, visited[100002];
vector <vector <int> > v(100005);
vector <int> izbrisi (vector <int> r, int x)
{
vector <int> t;
for (int i=0; i<r.size(); i++)
if (r[i] != x)
t.push_back(r[i]);
return t;
}
void dfs (int teme, int kraj)
{
if (teme == kraj)
{
l = true;
return;
}
visited[teme] = true;
for (int i=0; i<v[teme].size(); i++)
if (visited[v[teme][i]] == false)
{
dfs(v[teme][i], kraj);
if (l==true)
return;
}
}
int main()
{
int n, m;
cin >> n >> m;
for (int i=1; i<n; i++)
v[i].push_back(i+1);
for (int j=n+1; j<=2*n; j++)
v[j].push_back(j-1);
while (m--)
{
char x;
cin >> x;
if (x=='A')
{
int a,b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
if (x=='B')
{
int a,b;
cin >> a >> b;
if (a < b)
v[a] = izbrisi(v[a], b);
else
v[b] = izbrisi(v[b], a);
}
if (x=='Q')
{
int a,b;
cin >> a >> b;
l = false;
memset(visited,0,sizeof(visited));
dfs(a, b);
if (l==true)
cout << "DA" << endl;
else
cout << "NE" << endl;
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |