이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define lg long long
const lg N = 2e5+5;
lg par[N], compSize[N];
lg get(lg src)
{
if(src == par[src]) return src;
return par[src] = get(par[src]);
}
void join(lg u, lg v)
{
u = get(u), v = get(v);
if(u == v) return;
if(compSize[u] > compSize[v]) swap(u, v);
par[u] = v;
compSize[v] += compSize[u];
return;
}
int main()
{
#ifdef CYBER
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
lg n, k;
cin >> n >> k;
vector<lg> dat(n), tim(n);
for(int i = 1; i < n; i++) tim[i] = -1;
tim[0] = n;
lg op = 0;
k += n-1;
while(k--)
{
char c;
cin >> c;
if(c == 'S')
{
lg u, v;
cin >> u >> v;
u--, v--;
if(!v) swap(u, v);
tim[v] = op++;
}
else if(c == 'Q')
{
lg u, v;
cin >> u >> v;
u--, v--;
if(!u)
{
cout << (tim[v] == -1 ? "no\n" : "yes\n");
continue;
}
cout << ((tim[v] != -1 && tim[v] <= tim[u]) ? "yes\n" : "no\n");
}
else{
lg u;
cin >> u;
u--;
if(tim[u] == -1)
{
cout << "0\n";
continue;
}
cout << tim[u] << '\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... |
# | 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... |
# | 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... |