#include<bits/stdc++.h>
using namespace std;
//sub 1/2 trivial
//sub 3 path of smaller or larger edges
//sub task 4 binary tree can directly traverse the tree since logn height
//sub 5
//sub 6
#define pb push_back
#define fi first
#define se second
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
typedef pair<int,int> pii;
const int MAXN = 3e5;
vector<pii>adj[MAXN];
int cnt = 0,ans = 0;
bool dfs(int v,int u,int tar,int last){
if(v==tar)return 1;
bool ok = 0;
for(pii x:adj[v]){
if(x.fi==u)continue;
if(x.se < last)ok = ok|dfs(x.fi,v,tar,x.se);
}
return ok;
}
void dfs(int v,int u,int last){
ans++;
for(pii x:adj[v]){
if(x.fi==u)continue;
if(x.se > last)dfs(x.fi,u,x.se);
}
}
int main()
{
owo
int n,k;
cin>>n>>k;
for(int i=0;i<n+k-1;i++){
char c;
cin>>c;
if(c=='S'){
int v,u;
cin>>v>>u;
adj[v].pb({u,++cnt});
adj[u].pb({v,cnt});
}
if(c=='Q'){
int a,d;
cin>>a>>d;
if(dfs(a,0,d,1e9))cout<<"yes"<<'\n';
else cout<<"no"<<'\n';
}
if(c=='C'){
int d;cin>>d;
cout<<1<<'\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
8612 KB |
Output is correct |
2 |
Correct |
40 ms |
9196 KB |
Output is correct |
3 |
Correct |
237 ms |
9352 KB |
Output is correct |
4 |
Correct |
35 ms |
9268 KB |
Output is correct |
5 |
Correct |
37 ms |
9200 KB |
Output is correct |
6 |
Correct |
1286 ms |
9456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
8612 KB |
Output is correct |
2 |
Correct |
40 ms |
9196 KB |
Output is correct |
3 |
Correct |
237 ms |
9352 KB |
Output is correct |
4 |
Correct |
35 ms |
9268 KB |
Output is correct |
5 |
Correct |
37 ms |
9200 KB |
Output is correct |
6 |
Correct |
1286 ms |
9456 KB |
Output is correct |
7 |
Incorrect |
28 ms |
8492 KB |
Extra information in the output file |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
8604 KB |
Output is correct |
2 |
Execution timed out |
3561 ms |
10348 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
8604 KB |
Output is correct |
2 |
Execution timed out |
3561 ms |
10348 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
8532 KB |
Output is correct |
2 |
Correct |
103 ms |
14876 KB |
Output is correct |
3 |
Correct |
80 ms |
14792 KB |
Output is correct |
4 |
Execution timed out |
3557 ms |
12504 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
8532 KB |
Output is correct |
2 |
Correct |
103 ms |
14876 KB |
Output is correct |
3 |
Correct |
80 ms |
14792 KB |
Output is correct |
4 |
Execution timed out |
3557 ms |
12504 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8620 KB |
Output is correct |
2 |
Execution timed out |
3541 ms |
14924 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8620 KB |
Output is correct |
2 |
Execution timed out |
3541 ms |
14924 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8592 KB |
Output is correct |
2 |
Correct |
102 ms |
14848 KB |
Output is correct |
3 |
Correct |
90 ms |
14880 KB |
Output is correct |
4 |
Execution timed out |
3555 ms |
12304 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8592 KB |
Output is correct |
2 |
Correct |
102 ms |
14848 KB |
Output is correct |
3 |
Correct |
90 ms |
14880 KB |
Output is correct |
4 |
Execution timed out |
3555 ms |
12304 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8528 KB |
Output is correct |
2 |
Correct |
36 ms |
9168 KB |
Output is correct |
3 |
Correct |
255 ms |
9256 KB |
Output is correct |
4 |
Correct |
39 ms |
9224 KB |
Output is correct |
5 |
Correct |
34 ms |
9212 KB |
Output is correct |
6 |
Correct |
1417 ms |
9272 KB |
Output is correct |
7 |
Correct |
41 ms |
8588 KB |
Output is correct |
8 |
Execution timed out |
3564 ms |
10292 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8528 KB |
Output is correct |
2 |
Correct |
36 ms |
9168 KB |
Output is correct |
3 |
Correct |
255 ms |
9256 KB |
Output is correct |
4 |
Correct |
39 ms |
9224 KB |
Output is correct |
5 |
Correct |
34 ms |
9212 KB |
Output is correct |
6 |
Correct |
1417 ms |
9272 KB |
Output is correct |
7 |
Correct |
41 ms |
8588 KB |
Output is correct |
8 |
Execution timed out |
3564 ms |
10292 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |