# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
407410 | peuch | Simurgh (IOI17_simurgh) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "simurgh.h"
#include "simurgh.cpp"
#include <cstdio>
#include <cassert>
#include <vector>
#include <cstdlib>
#include <string>
using namespace std;
static int MAXQ = 30000;
static int N, M, Q = 0;
static vector<int> U, V;
static vector<bool> goal;
static void wrong_answer() {
printf("NO\n");
exit(0);
}
static bool is_valid(const vector<int>& r) {
if(int(r.size()) != N - 1)
return false;
for(int i = 0; i < N - 1; i++)
if (r[i] < 0 || r[i] >= M)
return false;
return true;
}
static int _count_common_roads_internal(const vector<int>& r) {
if(!is_valid(r))
wrong_answer();
int common = 0;
for(int i = 0; i < N - 1; i++) {
bool is_common = goal[r[i]];
if (is_common)
common++;
}
return common;
}
int count_common_roads(const vector<int>& r) {
Q++;
if(Q > MAXQ)
wrong_answer();
printf("\tTesting tree: ");
for(int i = 0; i < r.size(); i++)
printf("%d ", r[i]);
printf("\n");
return _count_common_roads_internal(r);
}
int main() {
assert(2 == scanf("%d %d", &N, &M));
U.resize(M);
V.resize(M);
for(int i = 0; i < M; i++)
assert(2 == scanf("%d %d", &U[i], &V[i]));
goal.resize(M, false);
for(int i = 0; i < N - 1; i++) {
int id;
assert(1 == scanf("%d", &id));
goal[id] = true;
}
vector<int> res = find_roads(N, U, V);
if(_count_common_roads_internal(res) != N - 1)
wrong_answer();
printf("YES\n");
return 0;
}