Submission #64096937
Source Code Expand
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007LL
//#define endl '\n'
#define pii pair<int,int>
#define Mikari_My_Wife ios::sync_with_stdio(0),cin.tie(0);
#define all(x) x.begin(),x.end()
using namespace std;
int n;
vector<int>v[500];
map<pii,int>vis;
int dep[505];
void dfs_pre(int now,int pre,int now_deep){
dep[now]=now_deep;
for(auto nxt:v[now]){
if(nxt==pre)continue;
dfs_pre(nxt,now,now_deep+1);
}
}
void solve(){
cin>>n;
for(int i=0;i<n-1;i++){
int x,y;
cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
vis[{x,y}]=1;
vis[{y,x}]=1;
}
dfs_pre(1,1,0);
set<pii>a;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
if(i==j||vis[{i,j}]||vis[{j,i}])continue;
if((dep[i]+dep[j])%2==1){
a.insert({i,j});
a.insert({j,i});
}
}
}
// for(auto [aa,bb]:a){
// cout<<aa<<"~"<<bb<<endl;
// }
if(a.size()/2%2==0){
cout<<"Second"<<endl;
int x,y;
while(cin>>x>>y){
if(x==-1&&y==-1)return ;
a.erase(a.find({x,y}));
a.erase(a.find({y,x}));
auto ow=*a.begin();
a.erase(a.begin());
cout<<ow.first<<" "<<ow.second<<endl;
a.erase(a.find({ow.second,ow.first}));
}
}else {
cout<<"First"<<endl;
auto ow=*a.begin();
a.erase(a.begin());
cout<<ow.first<<" "<<ow.second<<endl;
a.erase(a.find({ow.second,ow.first}));
int x,y;
while(cin>>x>>y){
if(x==-1&&y==-1)return ;
a.erase(a.find({x,y}));
a.erase(a.find({y,x}));
auto owo=*a.begin();
a.erase(a.begin());
cout<<owo.first<<" "<<owo.second<<endl;
a.erase(a.find({owo.second,owo.first}));
}
}
}
signed main(){
//注意多筆測資輸入!!!
//Mikari_My_Wife
int t=1;
//cin>>t;
while(t--){solve();}
}
Submission Info
| Submission Time |
|
| Task |
E - Tree Game |
| User |
zihan_ayame |
| Language |
C++ 20 (gcc 12.2) |
| Score |
425 |
| Code Size |
2135 Byte |
| Status |
AC |
| Exec Time |
13 ms |
| Memory |
4612 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
425 / 425 |
| Status |
AC
|
|
| Set Name |
Test Cases |
| Sample |
|
| All |
hand_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt |
| Case Name |
Status |
Exec Time |
Memory |
| hand_01.txt |
AC |
2 ms |
3688 KiB |
| random_01.txt |
AC |
12 ms |
4612 KiB |
| random_02.txt |
AC |
12 ms |
4404 KiB |
| random_03.txt |
AC |
12 ms |
4416 KiB |
| random_04.txt |
AC |
12 ms |
4556 KiB |
| random_05.txt |
AC |
12 ms |
4432 KiB |
| random_06.txt |
AC |
12 ms |
4344 KiB |
| random_07.txt |
AC |
13 ms |
4556 KiB |
| random_08.txt |
AC |
13 ms |
4340 KiB |
| random_09.txt |
AC |
4 ms |
4124 KiB |
| random_10.txt |
AC |
5 ms |
4188 KiB |
| random_11.txt |
AC |
4 ms |
4124 KiB |
| random_12.txt |
AC |
5 ms |
4160 KiB |
| random_13.txt |
AC |
6 ms |
4220 KiB |
| random_14.txt |
AC |
8 ms |
4308 KiB |
| random_15.txt |
AC |
6 ms |
4136 KiB |
| random_16.txt |
AC |
7 ms |
4308 KiB |
| random_17.txt |
AC |
12 ms |
4480 KiB |
| random_18.txt |
AC |
13 ms |
4420 KiB |
| random_19.txt |
AC |
13 ms |
4404 KiB |
| random_20.txt |
AC |
13 ms |
4492 KiB |
| random_21.txt |
AC |
8 ms |
4036 KiB |
| random_22.txt |
AC |
2 ms |
3808 KiB |
| random_23.txt |
AC |
2 ms |
3856 KiB |
| random_24.txt |
AC |
4 ms |
3844 KiB |
| random_25.txt |
AC |
3 ms |
3860 KiB |
| random_26.txt |
AC |
10 ms |
4232 KiB |
| random_27.txt |
AC |
11 ms |
4324 KiB |
| random_28.txt |
AC |
3 ms |
3764 KiB |