# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
552221 | LucaDantas | Jail (JOI22_jail) | C++17 | 5084 ms | 396 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 251, maxm = 6;
int p[maxn], depth[maxn];
vector<int> g[maxn];
void dfs(int u) {
for(int v : g[u]) if(v != p[u]) {
p[v] = u;
depth[v] = depth[u] + 1;
dfs(v);
}
}
void clear(int n) {
for(int i = 0; i <= n; i++)
g[i].clear(), p[i] = 0, depth[i] = 0;
}
int s[maxm], t[maxm];
bool mark[maxn];
bool fine(int a, int b) {
bool ok = !mark[b]; // b é pra ser meu final, se tem alguém la já fudeu
// pode ter gente no a que no caso sou eu mesmo
// printf("comeco %d %d\n", a, b);
for(; a != b;) {
if(depth[a] < depth[b])
swap(a, b);
a = p[a];
ok &= !mark[a];
// printf("%d %d\n", a, b);
}
// printf("fim %d\n", ok);
return ok;
}
int main() {
int q; scanf("%d", &q);
while(q--) {
int n; scanf("%d", &n);
clear(n);
for(int i = 1, a, b; i < n; i++)
scanf("%d %d", &a, &b), g[a].push_back(b), g[b].push_back(a);
dfs(1);
int m; scanf("%d", &m);
for(int i = 0; i < m; i++)
scanf("%d %d", s+i, t+i);
vector<int> ord(m); iota(ord.begin(), ord.end(), 0);
bool ans = 0;
do {
bool ok = 1;
for(int i = 0; i < m; i++)
mark[s[i]] = 1;
for(int i = 0; i < m; i++) {
int now = ord[i];
mark[s[now]] = 0;
ok &= fine(s[now], t[now]);
mark[t[now]] = 1;
}
for(int i = 0; i < m; i++)
mark[t[i]] = 0;
ans |= ok;
// puts("PROXIMA\n");
} while(next_permutation(ord.begin(), ord.end()));
puts(ans ? "Yes" : "No");
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |