# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
872109 |
2023-11-12T10:19:28 Z |
mgl_diamond |
Jail (JOI22_jail) |
C++17 |
|
2 ms |
3256 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define file "input"
template<class T> bool maximize(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool minimize(T &a, T b) { if (a > b) { a = b; return 1; } return 0; }
void setIO() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(file".inp", "r")) {
freopen(file".inp", "r", stdin);
freopen(file".out", "w", stdout);
}
}
const int N = 120002;
int q, n, m;
vector<int> graph[N];
int main() {
setIO();
cin >> q;
while (q--) {
cin >> n >> m;
foru(i, 1, n) {
graph[i].clear();
}
foru(i, 2, n) {
int u, v;
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
vector<ii> pos[2];
int mn = N, mx = -N;
foru(i, 1, m) {
int u, v;
cin >> u >> v;
pos[u > v].emplace_back(u, v);
if (u > v) minimize(mn, v);
if (u < v) maximize(mx, v);
}
sort(all(pos[0]));
sort(all(pos[1]), greater<ii>());
// fore(x, pos[0]) cout << x.first << " " << x.second << "\n";
bool can = 1;
if (mn < mx) can = 0;
if (!pos[0].empty() && !pos[1].empty())
if (pos[0].back() >= pos[1][0])
can = 0;
foru(i, 0, sz(pos[0])-2)
if (pos[0][i].second > pos[0][i+1].second)
can = 0;
foru(i, 0, sz(pos[1])-2)
if (pos[1][i].second < pos[1][i+1].second)
can = 0;
cout << (can ? "Yes\n" : "No\n");
}
}
Compilation message
jail.cpp: In function 'void setIO()':
jail.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen(file".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jail.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen(file".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3256 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |