提出 #38804839
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast") // -Ofast 预编译优化
#define lp (p << 1)
#define rp ((p << 1)|1)
#define ll long long
#define ld long double
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(x) (int)(x).size()
#define fastio cin.tie(0) -> sync_with_stdio(0)
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define F(i, a, b) for(int i=(a); i <= (b); ++i)
#define SUM 1
#define MAX 0
#define fi first
#define se second
#define il inline
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define PQ(TYPE, FUNCTOR) priority_queue<TYPE, vector<TYPE>, FUNCTOR<TYPE>>
#define HERE printf("HERE, __LINE__==%d\n", __LINE__);
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fll
template<typename T, T...>
struct myinteger_sequence { };
template<typename T, typename S1 = void, typename S2 = void>
struct helper{
std::string operator()(const T& s){
return std::string(s);
}
};
template<typename T>
struct helper<T, decltype((void)std::to_string(std::declval<T>())), typename std::enable_if<!std::is_same<typename std::decay<T>::type, char>::value, void>::type>{
std::string operator()(const T& s){
return std::to_string(s);
}
};
template<typename T>
struct helper<T, void, typename std::enable_if<std::is_same<typename std::decay<T>::type, char>::value, void>::type>{
std::string operator()(const T& s){
return std::string(1, s);
}
};
template<typename T, typename S1 =void, typename S2 =void>
struct seqhelper{
const static bool seq = false;
};
template<typename T>
struct seqhelper<T, decltype((void)(std::declval<T>().begin())), decltype((void)(std::declval<T>().end()))>{
const static bool seq = !(std::is_same<typename std::decay<T>::type, std::string>::value);
};
template<std::size_t N, std::size_t... I>
struct gen_indices : gen_indices<(N - 1), (N - 1), I...> { };
template<std::size_t... I>
struct gen_indices<0, I...> : myinteger_sequence<std::size_t, I...> { };
template<typename T, typename REDUNDANT = void>
struct converter{
template<typename H>
std::string& to_string_impl(std::string& s, H&& h)
{
using std::to_string;
s += converter<H>().convert(std::forward<H>(h));
return s;
}
template<typename H, typename... T1>
std::string& to_string_impl(std::string& s, H&& h, T1&&... t)
{
using std::to_string;
s += converter<H>().convert(std::forward<H>(h)) + ", ";
return to_string_impl(s, std::forward<T1>(t)...);
}
template<typename... T1, std::size_t... I>
std::string mystring(const std::tuple<T1...>& tup, myinteger_sequence<std::size_t, I...>)
{
std::string result;
int ctx[] = { (to_string_impl(result, std::get<I>(tup)...), 0), 0 };
(void)ctx;
return result;
}
template<typename... S>
std::string mystring(const std::tuple<S...>& tup)
{
return mystring(tup, gen_indices<sizeof...(S)>{});
}
template<typename S=T>
std::string convert(const S& x){
return helper<S>()(x);
}
template<typename... S>
std::string convert(const std::tuple<S...>& tup){
std::string res = std::move(mystring(tup));
res = "{" + res + "}";
return res;
}
template<typename S1, typename S2>
std::string convert(const std::pair<S1, S2>& x){
return "{" + converter<S1>().convert(x.first) + ", " + converter<S2>().convert(x.second) + "}";
}
};
template<typename T>
struct converter<T, typename std::enable_if<seqhelper<T>::seq, void>::type>{
template<typename S=T>
std::string convert(const S& x){
int len = 0;
std::string ans = "{";
for(auto it = x.begin(); it != x.end(); ++it){
ans += move(converter<typename S::value_type>().convert(*it)) + ", ";
++len;
}
if(len == 0) return "{[EMPTY]}";
ans.pop_back(), ans.pop_back();
return ans + "}";
}
};
template<typename T>
std::string luangao(const T& x){
return converter<T>().convert(x);
}
//jiangly Codeforces
constexpr int P = 998244353;
using i64 = long long;
// assume -P <= x < 2P
int norm(int x) {
if (x < 0) {
x += P;
}
if (x >= P) {
x -= P;
}
return x;
}
template<class T>
T power(T a, i64 b) {
T res = 1;
for (; b; b /= 2, a *= a) {
if (b % 2) {
res *= a;
}
}
return res;
}
struct Z {
int x;
Z(int x = 0) : x(norm(x)) {}
Z(i64 x) : x(norm((int)(x % P))) {}
int val() const {
return x;
}
Z operator-() const {
return Z(norm(P - x));
}
Z inv() const {
assert(x != 0);
return power(*this, P - 2);
}
Z &operator*=(const Z &rhs) {
x = i64(x) * rhs.x % P;
return *this;
}
Z &operator+=(const Z &rhs) {
x = norm(x + rhs.x);
return *this;
}
Z &operator-=(const Z &rhs) {
x = norm(x - rhs.x);
return *this;
}
Z &operator/=(const Z &rhs) {
return *this *= rhs.inv();
}
friend Z operator*(const Z &lhs, const Z &rhs) {
Z res = lhs;
res *= rhs;
return res;
}
friend Z operator+(const Z &lhs, const Z &rhs) {
Z res = lhs;
res += rhs;
return res;
}
friend Z operator-(const Z &lhs, const Z &rhs) {
Z res = lhs;
res -= rhs;
return res;
}
friend Z operator/(const Z &lhs, const Z &rhs) {
Z res = lhs;
res /= rhs;
return res;
}
friend std::istream &operator>>(std::istream &is, Z &a) {
i64 v;
is >> v;
a = Z(v);
return is;
}
friend std::ostream &operator<<(std::ostream &os, const Z &a) {
return os << a.val();
}
};
template<typename T>
vector<pair<T, T>> factorize(T x){
vector<pair<T, T>> primes;
for (T p = 2; p * p <= x; ++p) {
if (x % p == 0) {
T k = 1;
for (x /= p; x % p == 0; x /= p) ++k;
primes.push_back({p, k});
}
}
if (x > T(1)) primes.push_back({x, T(1)});
return primes;
}
template<typename T>
void facmap(T x, map<T, T>& primes){
for (T p = 2; p * p <= x; ++p) {
if (x % p == 0) {
T k = 1;
for (x /= p; x % p == 0; x /= p) ++k;
primes[p] += k;
}
}
if (x > T(1)) primes[x] += T(1);
}
ll intsqrt (ll x) {
ll ans = 0;
for (ll k = 1LL << 30; k != 0; k /= 2) {
if ((ans + k) * (ans + k) <= x) {
ans += k;
}
}
return ans;
}
template<typename T>
T gcd(ll x, T y) {
if (!y) return x;
return gcd(y, x % y);
}
template<typename T>
T exgcd(T a, T b, T &x, T &y) {//exgcd 求逆元
if (!b) {
x = 1;
y = 0;
return a;
}
T re = exgcd(b, a % b, y, x);
y -= x * (a / b);
return re;
}
#define DEBUG 0
#define SINGLE 0
void debug(const char* p){
#if DEBUG
freopen(p, "r", stdin);
#else
fastio;
#endif
}
#define C 2005
int c[C];
vector<int> out[C];
vector<int> vis[C];
int n, m;
struct dis{
int x, y, d;
};
int bfs(int x, int y, int tx, int ty){
queue<dis> q;
vis[x][y] = 1;
q.push(dis{x, y, 0});
while(!q.empty()){
auto t = q.front();
q.pop();
int i = t.x, j = t.y, l = t.d;
if(i == tx && j == ty){
return l;
}
for(int ni: out[i]){
for(int nj: out[j]){
if(c[ni] != c[nj] && !vis[ni][nj]){
q.push(dis{ni, nj, l+1});
vis[ni][nj] = 1;
}
}
}
}
return -1;
}
void solve(int test){
cin >> n >> m;
F(i, 1, n) {
cin >> c[i];
out[i].clear();
vis[i].clear();
vis[i].resize(n+1);
F(j, 1, n){
vis[i][j] = 0;
}
}
F(i, 1, m){
int ui, vi;
cin >> ui >> vi;
out[ui].pb(vi);
out[vi].pb(ui);
}
int res = bfs(1, n, n, 1);
cout << res << "\n";
}
signed main(int argc, char** argv){
debug(argc==1?"test1.txt":argv[1]);
int t = 1;
int test = 0;
#if !SINGLE
cin >> t;
#endif
while(t--){
solve(test++);
}
}
提出情報
コンパイルエラー
./Main.cpp: In function ‘void debug(const char*)’:
./Main.cpp:284:24: warning: unused parameter ‘p’ [-Wunused-parameter]
284 | void debug(const char* p){
| ~~~~~~~~~~~~^
./Main.cpp: In function ‘void solve(int)’:
./Main.cpp:325:16: warning: unused parameter ‘test’ [-Wunused-parameter]
325 | void solve(int test){
| ~~~~^~~~
ジャッジ結果
セット名 |
Sample |
All |
得点 / 配点 |
0 / 0 |
500 / 500 |
結果 |
|
|
セット名 |
テストケース |
Sample |
00_sample_00.txt |
All |
00_sample_00.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 01_small_09.txt, 01_small_10.txt, 01_small_11.txt, 01_small_12.txt, 01_small_13.txt, 01_small_14.txt, 01_small_15.txt, 01_small_16.txt, 01_small_17.txt, 01_small_18.txt, 01_small_19.txt, 01_small_20.txt, 01_small_21.txt, 01_small_22.txt, 01_small_23.txt, 01_small_24.txt, 01_small_25.txt, 01_small_26.txt, 01_small_27.txt, 01_small_28.txt, 01_small_29.txt, 01_small_30.txt, 01_small_31.txt, 02_tree_00.txt, 02_tree_01.txt, 02_tree_02.txt, 02_tree_03.txt, 02_tree_04.txt, 02_tree_05.txt, 03_path_00.txt, 03_path_01.txt, 03_path_02.txt, 03_path_03.txt, 04_dense_00.txt, 04_dense_01.txt, 04_dense_02.txt, 04_dense_03.txt, 05_sparse_00.txt, 05_sparse_01.txt, 05_sparse_02.txt, 05_sparse_03.txt, 06_large_00.txt, 06_large_01.txt, 06_large_02.txt, 06_large_03.txt, 06_large_04.txt, 06_large_05.txt, 06_large_06.txt, 06_large_07.txt, 06_large_08.txt, 06_large_09.txt, 07_bridge_connected_00.txt, 07_bridge_connected_01.txt, 07_bridge_connected_02.txt |
ケース名 |
結果 |
実行時間 |
メモリ |
00_sample_00.txt |
AC |
5 ms |
3564 KiB |
01_small_00.txt |
AC |
3 ms |
3644 KiB |
01_small_01.txt |
AC |
2 ms |
3696 KiB |
01_small_02.txt |
AC |
5 ms |
3716 KiB |
01_small_03.txt |
AC |
2 ms |
3700 KiB |
01_small_04.txt |
AC |
2 ms |
3592 KiB |
01_small_05.txt |
AC |
3 ms |
3712 KiB |
01_small_06.txt |
AC |
3 ms |
3636 KiB |
01_small_07.txt |
AC |
3 ms |
3596 KiB |
01_small_08.txt |
AC |
5 ms |
3612 KiB |
01_small_09.txt |
AC |
2 ms |
3584 KiB |
01_small_10.txt |
AC |
2 ms |
3664 KiB |
01_small_11.txt |
AC |
3 ms |
3620 KiB |
01_small_12.txt |
AC |
3 ms |
3700 KiB |
01_small_13.txt |
AC |
3 ms |
3700 KiB |
01_small_14.txt |
AC |
3 ms |
3692 KiB |
01_small_15.txt |
AC |
3 ms |
3660 KiB |
01_small_16.txt |
AC |
4 ms |
3588 KiB |
01_small_17.txt |
AC |
3 ms |
3584 KiB |
01_small_18.txt |
AC |
4 ms |
3696 KiB |
01_small_19.txt |
AC |
7 ms |
3660 KiB |
01_small_20.txt |
AC |
3 ms |
3668 KiB |
01_small_21.txt |
AC |
3 ms |
3612 KiB |
01_small_22.txt |
AC |
5 ms |
3624 KiB |
01_small_23.txt |
AC |
4 ms |
3700 KiB |
01_small_24.txt |
AC |
7 ms |
3608 KiB |
01_small_25.txt |
AC |
8 ms |
3740 KiB |
01_small_26.txt |
AC |
10 ms |
3708 KiB |
01_small_27.txt |
AC |
8 ms |
3636 KiB |
01_small_28.txt |
AC |
13 ms |
3732 KiB |
01_small_29.txt |
AC |
5 ms |
3584 KiB |
01_small_30.txt |
AC |
8 ms |
3616 KiB |
01_small_31.txt |
AC |
8 ms |
3676 KiB |
02_tree_00.txt |
AC |
20 ms |
19436 KiB |
02_tree_01.txt |
AC |
18 ms |
19368 KiB |
02_tree_02.txt |
AC |
20 ms |
19224 KiB |
02_tree_03.txt |
AC |
24 ms |
19360 KiB |
02_tree_04.txt |
AC |
20 ms |
19384 KiB |
02_tree_05.txt |
AC |
24 ms |
19452 KiB |
03_path_00.txt |
AC |
77 ms |
19440 KiB |
03_path_01.txt |
AC |
21 ms |
19356 KiB |
03_path_02.txt |
AC |
20 ms |
19228 KiB |
03_path_03.txt |
AC |
19 ms |
19392 KiB |
04_dense_00.txt |
AC |
20 ms |
3752 KiB |
04_dense_01.txt |
AC |
17 ms |
3752 KiB |
04_dense_02.txt |
AC |
21 ms |
3728 KiB |
04_dense_03.txt |
AC |
17 ms |
3676 KiB |
05_sparse_00.txt |
AC |
35 ms |
19844 KiB |
05_sparse_01.txt |
AC |
18 ms |
19424 KiB |
05_sparse_02.txt |
AC |
18 ms |
19272 KiB |
05_sparse_03.txt |
AC |
21 ms |
19328 KiB |
06_large_00.txt |
AC |
71 ms |
19344 KiB |
06_large_01.txt |
AC |
66 ms |
19356 KiB |
06_large_02.txt |
AC |
64 ms |
19292 KiB |
06_large_03.txt |
AC |
68 ms |
19248 KiB |
06_large_04.txt |
AC |
67 ms |
19256 KiB |
06_large_05.txt |
AC |
68 ms |
19408 KiB |
06_large_06.txt |
AC |
67 ms |
19392 KiB |
06_large_07.txt |
AC |
67 ms |
19352 KiB |
06_large_08.txt |
AC |
64 ms |
19376 KiB |
06_large_09.txt |
AC |
70 ms |
19396 KiB |
07_bridge_connected_00.txt |
AC |
51 ms |
12580 KiB |
07_bridge_connected_01.txt |
AC |
52 ms |
12576 KiB |
07_bridge_connected_02.txt |
AC |
14 ms |
12372 KiB |