답안 #1048314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1048314 2024-08-08T06:42:52 Z 정민찬(#11037) Make them Meet (EGOI24_makethemmeet) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

int N, M;
vector<int> adj[110];
vector<int> g[110];
int vis[110];

void make_tree(int x) {
    vis[x] = 1;
    for (auto &y : adj[x]) {
        if (vis[y]) continue;
        g[x].push_back(y);
        make_tree(y);
    }
}

vector<vector<int>> ans;

void travel(int x) {
    vector<int> qry(N);
    for (auto &y : g[x]) {
        iota(qry.begin(), qry.end(), 1);
        qry[x] = 0;
        qry[y] = 0;
        ans.push_back(qry);
        travel(y);
        ans.push_back(qry);
    }
}

int down[110];

void construct(int x) {
    if (g[x].empty()) return;
    vector<int> qry(N);
    for (auto &y : g[x]) {
        if (g[y].empty()) return;
        iota(qry.begin(), qry.end(), 1);
        qry[x] = 0;
        qry[y] = 0;
        ans.push_back(qry);
        construct(y);
        ans.push_back(qry);
    }
    
    iota(qry.begin(), qry.end(), 1);
    qry[x] = 0;
    for (auto &y : g[x]) qry[y] = 0;
    ans.push_back(qry);
    if (g[x].size() > 1) {
        for (auto &y : g[x]) {
            iota(qry.begin(), qry.end(), 1);
            qry[x] = 0;
            qry[y] = 0;
            ans.push_back(qry);
            ans.push_back(qry);
        }
    }
    vector<int> t;
    for (auto &y : g[x]) {
        if (down[y] != -1) {
            t.push_back(y);
        }
    }
    if (t.empty()) {
        down[x] = g[x][0];
        iota(qry.begin(), qry.end(), 1);
        qry[x] = 0;
        qry[down[x]] = 0;
        ans.push_back(qry);
        return;
    }
    if (t.size() > 1) {
        iota(qry.begin(), qry.end(), 1);
        qry[x] = 0;
        qry[t[0]] = 0;
        ans.push_back(qry);
        for (int i=1; i<t.size(); i++) {
            iota(qry.begin(), qry.end(), 1);
            qry[t[i]] = 0;
            qry[down[t[i]]] = 0;
            ans.push_back(qry);
        }
        iota(qry.begin(), qry.end(), 1);
        qry[x] = 0;
        for (auto &y : t) qry[y] = 0;
        ans.push_back(qry);
        for (auto &y : t) {
            iota(qry.begin(), qry.end(), 1);
            qry[x] = 0;
            qry[y] = 0;
            ans.push_back(qry);
            ans.push_back(qry);
        }
    }
    iota(qry.begin(), qry.end(), 1);
    qry[x] = 0;
    qry[t[0]] = 0;
    qry[down[t[0]]] = 0;
    ans.push_back(qry);
    down[x] = t[0];
}

int main() {
    ios_base :: sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> M;
    for (int i=0; i<M; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    make_tree(0);
    travel(0);
    memset(down, -1, sizeof(down));
    construct(0);
    cout << ans.size() << '\n';
    for (int i=0; i<ans.size(); i++) {
        for (int j=0; j<N; j++) {
            cout << ans[i][j] << ' ';
        }
        cout << '\n';
    }
}

Compilation message

Main.cpp: In function 'void construct(int)':
Main.cpp:83:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         for (int i=1; i<t.size(); i++) {
      |                       ~^~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:123:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |     for (int i=0; i<ans.size(); i++) {
      |                   ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB If people start at 1 and 2, then they can avoid each other
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 344 KB If people start at 1 and 2, then they can avoid each other
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB If people start at 1 and 2, then they can avoid each other
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB If people start at 1 and 2, then they can avoid each other
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB If people start at 1 and 2, then they can avoid each other
3 Halted 0 ms 0 KB -