結果

問題 No.1153 ねこちゃんゲーム
ユーザー n_vipn_vip
提出日時 2020-08-07 21:49:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 317 ms / 2,500 ms
コード長 4,017 bytes
コンパイル時間 2,130 ms
コンパイル使用メモリ 141,052 KB
実行使用メモリ 37,344 KB
最終ジャッジ日時 2023-10-25 00:44:01
合計ジャッジ時間 19,150 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 200 ms
28,368 KB
testcase_08 AC 204 ms
28,368 KB
testcase_09 AC 207 ms
28,368 KB
testcase_10 AC 200 ms
28,368 KB
testcase_11 AC 206 ms
28,368 KB
testcase_12 AC 201 ms
28,368 KB
testcase_13 AC 209 ms
28,368 KB
testcase_14 AC 224 ms
28,368 KB
testcase_15 AC 233 ms
28,368 KB
testcase_16 AC 227 ms
28,368 KB
testcase_17 AC 259 ms
28,368 KB
testcase_18 AC 203 ms
28,368 KB
testcase_19 AC 204 ms
28,368 KB
testcase_20 AC 201 ms
28,632 KB
testcase_21 AC 207 ms
28,632 KB
testcase_22 AC 210 ms
28,368 KB
testcase_23 AC 222 ms
28,368 KB
testcase_24 AC 222 ms
28,368 KB
testcase_25 AC 218 ms
28,368 KB
testcase_26 AC 241 ms
28,368 KB
testcase_27 AC 304 ms
37,080 KB
testcase_28 AC 297 ms
37,344 KB
testcase_29 AC 317 ms
36,552 KB
testcase_30 AC 279 ms
36,288 KB
testcase_31 AC 281 ms
33,120 KB
testcase_32 AC 172 ms
29,696 KB
testcase_33 AC 163 ms
29,692 KB
testcase_34 AC 171 ms
29,696 KB
testcase_35 AC 176 ms
29,692 KB
testcase_36 AC 169 ms
29,696 KB
testcase_37 AC 104 ms
29,768 KB
testcase_38 AC 87 ms
29,768 KB
testcase_39 AC 95 ms
29,768 KB
testcase_40 AC 98 ms
29,960 KB
testcase_41 AC 82 ms
29,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"
#define cauto const auto

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
template<class A,class B> pair<A,B> operator+(const pair<A,B> &p,const pair<A,B> &q){ return {p.X+q.X,p.Y+q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator+=(pair<A,B> &p,const pair<C,D> &q){ p.X+=q.X; p.Y+=q.Y; return p;}
template<class A,class B> pair<A,B> operator-(const pair<A,B> &p,const pair<A,B> &q){ return {p.X-q.X,p.Y-q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator-=(pair<A,B> &p,const pair<C,D> &q){ p.X-=q.X; p.Y-=q.Y; return p;}
template<class A,class B> istream& operator>>(istream &is, pair<A,B> &p){ is>>p.X>>p.Y; return is;}
template<class T=ll> T read(){ T re; cin>>re; return move(re);}
template<class T=ll> T read(const T &dec){ T re; cin>>re; return re-dec;}
template<class T=ll> vector<T> readV(const int sz){ vector<T> re(sz); for(auto &x:re) x=read<T>(); return move(re);}
template<class T=ll> vector<T> readV(const int sz, const T &dec){ vector<T> re(sz); for(auto &x:re) x=read<T>(dec); return move(re);}
vv<int> readG(const int &n,const int &m){ vv<int> g(n); rep(_,m){ cauto a=read<int>(1),b=read<int>(1); g[a].pb(b); g[b].pb(a);} return move(g);}
vv<int> readG(const int &n){ return readG(n,n-1);}
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	cauto n=read();
	cauto m=read();
	cauto as=readV(m,1);
	cauto g=readG(n);
	vv<int> cnts(n);
	rep(i,n) cnts[i].resize(g[i].size()+1);
	vector<int> grs0(n),par(n);
	{
		auto dfs=
			[&](auto &&dfs,int v,int p)->void{
				par[v]=p;
				for(auto w:g[v])if(p!=w){
						dfs(dfs,w,v);
						if(grs0[w]<cnts[v].size())	++cnts[v][grs0[w]];
					}
				while(cnts[v][grs0[v]]) ++grs0[v];
			};
		dfs(dfs,0,-1);
	}
	{
		auto dfs=
			[&](auto &&dfs,int v,int p,int pr)->void{
				if(pr<cnts[v].size()) ++cnts[v][pr];
				int cur=0;
				while(cnts[v][cur]) ++cur;
				for(auto w:g[v])if(p!=w){
						dfs(dfs,w,v,(grs0[w]<cnts[v].size() && cnts[v][grs0[w]]==1)?min(cur,grs0[w]):cur);
					}
			};
		dfs(dfs,0,-1,MOD);
	}
	vector<int> grs(n);
	rep(v,n)while(cnts[v][grs[v]]) ++grs[v];
	out(grs,1);
	int re=0;
	for(auto a:as) re^=grs[a];
	out(re,1);
	if(re==0){
		cout<<"-1 -1" NL;
		return 0;
	}
	rep(i,m){
		auto v=as[i];
		if(auto tgt=(grs[v]^re); tgt<grs[v]){
			int nxt=par[v];
			for(auto w:g[v])if(w!=par[v] && grs0[w]==tgt) nxt=w;
			cout<<i+1<<" "<<nxt+1<<endl;;
			return 0;
		}
	}
  return 0;
}
0