提出 #64057106


ソースコード 拡げる

// 내가 더 잘할게요 이렇게 같이 있어준다면
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,a,b) for (int i = (a); i < (b); i++)

#define ll long long
#define ar array
#define pb push_back
int N;
vector<vector<int>> adj;
vector<int> color;  

void dfs(int v, int c) {
    color[v] = c;
    for (int nv : adj[v]) {
        if (color[nv] == -1) {
            dfs(nv, c^1);
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;
    adj.assign(N+1, vector<int>());
    color.assign(N+1, -1);

    set<pair<int,int>> usedEdges;
    rep(i, 1, N) {
        int u, v;
        cin >> u >> v;
        if(u > v) swap(u, v);
        usedEdges.insert({u, v});
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    dfs(1, 0);
    
    vector<int> part0, part1;
    rep(i, 1, N+1) {
        if(color[i] == 0)
            part0.push_back(i);
        else
            part1.push_back(i);
    }
    
    set<pair<int,int>> avail;
    for (int a : part0) {
        for (int b : part1) {
            int i = min(a, b), j = max(a, b);
            if(usedEdges.find({i, j}) == usedEdges.end()){
                avail.insert({i, j});
            }
        }
    }
    
    int totalMoves = avail.size();
    bool playFirst = (totalMoves % 2 == 1);
    
    if(playFirst){
        cout << "First" << "\n";
        cout.flush();
    } else {
        cout << "Second" << "\n";
        cout.flush();
    }
    
    bool myTurn = playFirst;
    while(true) {
        if(myTurn) {
            if(avail.empty()){
                break;
            }
            auto it = avail.begin();
            int i = it->first, j = it->second;
            avail.erase(it);
            cout << i << " " << j << "\n";
            cout.flush();
        }
        int u, v;
        if(!(cin >> u >> v)) break; 
        if(u == -1 && v == -1){
            break;
        }
        int a = min(u, v), b = max(u, v);
        avail.erase({a, b});
        myTurn = true; 
    }
    return 0;
}

提出情報

提出日時
問題 E - Tree Game
ユーザ reform
言語 C++ 17 (gcc 12.2)
得点 425
コード長 2172 Byte
結果 AC
実行時間 10 ms
メモリ 3996 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 425 / 425
結果 AC
AC × 29
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
hand_01.txt AC 2 ms 3736 KiB
random_01.txt AC 10 ms 3816 KiB
random_02.txt AC 10 ms 3916 KiB
random_03.txt AC 10 ms 3876 KiB
random_04.txt AC 10 ms 3900 KiB
random_05.txt AC 10 ms 3996 KiB
random_06.txt AC 10 ms 3792 KiB
random_07.txt AC 10 ms 3928 KiB
random_08.txt AC 10 ms 3928 KiB
random_09.txt AC 2 ms 3772 KiB
random_10.txt AC 4 ms 3796 KiB
random_11.txt AC 3 ms 3680 KiB
random_12.txt AC 4 ms 3832 KiB
random_13.txt AC 4 ms 3720 KiB
random_14.txt AC 6 ms 3784 KiB
random_15.txt AC 4 ms 3700 KiB
random_16.txt AC 5 ms 3740 KiB
random_17.txt AC 10 ms 3864 KiB
random_18.txt AC 10 ms 3808 KiB
random_19.txt AC 10 ms 3808 KiB
random_20.txt AC 10 ms 3936 KiB
random_21.txt AC 7 ms 3872 KiB
random_22.txt AC 3 ms 3672 KiB
random_23.txt AC 2 ms 3856 KiB
random_24.txt AC 4 ms 3736 KiB
random_25.txt AC 3 ms 3860 KiB
random_26.txt AC 8 ms 3880 KiB
random_27.txt AC 9 ms 3836 KiB
random_28.txt AC 3 ms 3676 KiB