# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
765269 |
2023-06-24T10:05:05 Z |
canadavid1 |
Joker (BOI20_joker) |
C++14 |
|
205 ms |
10132 KB |
#include <bits/stdc++.h>
using namespace std;
vector<bool> diff;
vector<int> p;
vector<int> siz;
pair<int,bool> find(int a,bool len=0)
{
if (p[a] == -1) return {a,len};
return find(p[a],len^diff[a]); // no path compression
}
bool unite(int a,int b) // true if works, false elsewise
{
auto av = find(a);
auto bv = find(b);
if (av.first == bv.first) return av.second!=bv.second;
if (siz[av.first] > siz[bv.first]) swap(av,bv);
// b > a
p[av.first] = bv.first;
siz[bv.first] += siz[av.first];
if (av.second == bv.second) diff[av.first] = true;
return true;
}
vector<pair<int,int>> edge;
vector<pair<int,int>> query;
vector<bool> queryvalid;
int N,M,Q,added;
int main()
{
cin >> N >> M >> Q;
diff.assign(N+1,false);
p.assign(N+1,-1);
siz.assign(N+1,1);
queryvalid.assign(Q,false);
edge.push_back({0,0});
for(int i = 0; i < M; i++)
{
int l,r;
cin >> l >> r;
edge.push_back({l,r});
}
for(int i = 0; i < Q; i++)
{
int l,r;
cin >> l >> r;
query.push_back({r,i});
}
sort(query.begin(),query.end());
added = M;
bool valid = true;
while(query.size())
{
for(;added>query.back().first;added--)
{
valid &= unite(edge[added].first,edge[added].second);
}
queryvalid[query.back().second] = valid;
query.pop_back();
}
for (auto &&i : queryvalid)
{
cout << (i ? "NO\n" : "YES\n");
}
/*
vector<vector<int>> neigh(N+1);
vector<pair<int,int>> edge;
for(int i = 0; i < N; i++)
{
int u,v;
cin >> u >> v;
neigh[u].push_back(v);
neigh[v].push_back(u);
edge.push_back({u,v});
}
vector<pair<int,int>> query(Q);
int l;
for (auto &&r : query) cin >> l >> r.first;
for(int i = 0; i < Q; i++) query[i].second = i;
sort(query.begin(),query.end());
vector<bool> result;
int s;
while(query.size())
{
}*/
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
178 ms |
5748 KB |
Output is correct |
4 |
Correct |
172 ms |
6804 KB |
Output is correct |
5 |
Correct |
189 ms |
6608 KB |
Output is correct |
6 |
Correct |
185 ms |
9240 KB |
Output is correct |
7 |
Correct |
188 ms |
9272 KB |
Output is correct |
8 |
Correct |
163 ms |
8544 KB |
Output is correct |
9 |
Correct |
191 ms |
8844 KB |
Output is correct |
10 |
Correct |
182 ms |
9932 KB |
Output is correct |
11 |
Correct |
185 ms |
9356 KB |
Output is correct |
12 |
Correct |
204 ms |
9996 KB |
Output is correct |
13 |
Correct |
200 ms |
8560 KB |
Output is correct |
14 |
Correct |
182 ms |
8996 KB |
Output is correct |
15 |
Correct |
182 ms |
9652 KB |
Output is correct |
16 |
Correct |
205 ms |
10132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |