QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#59928#4996. Icy ItinerarySa3tElSefrWA 5ms18020kbC++202.0kb2022-11-02 04:34:322022-11-02 04:34:35

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-02 04:34:35]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:18020kb
  • [2022-11-02 04:34:32]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>

#define ll long long
#define ld  double
using namespace std;

const int N = 3e5 + 5, lg = 19, mod = 998244353;


set<int> adj[N];

int L[N], R[N];


bool tmam(int node) {
    if(L[node] == 0 || R[node] == 0) return 0;
    bool x = adj[node].find(L[node]) != adj[node].end();
    bool y = adj[node].find(R[node]) != adj[node].end();
    return (x ^ y);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].insert(v);
        adj[v].insert(u);
    }

    R[1] = 2;
    L[2] = 1;
    int curMid = 2;

    int directEdge = (adj[1].find(2) != adj[1].end());
    int noEdge = (adj[1].find(2) == adj[1].end());

    for(int i = 3; i <= n; i++) {
        if(directEdge && noEdge) {

            if(tmam(L[curMid])) curMid = L[curMid];
            else if(tmam(R[curMid])) curMid = R[curMid];

            bool X = (adj[curMid].find(L[curMid]) != adj[curMid].end());
            bool Y = (adj[curMid].find(i) != adj[curMid].end());


            // direct direct direct direct undirect undirect
            if(X == Y) {
                L[R[curMid]] = i;
                R[curMid] = i;
                L[i] = curMid;
            }
            else {
                R[L[curMid]] = i;
                L[curMid] = i;
                R[i] = curMid;
            }
        }
        else {
            R[curMid] = i;
            L[i] = curMid;
            directEdge |= (adj[curMid].find(i) != adj[curMid].end());
            noEdge |= (adj[curMid].find(i) == adj[curMid].end());
            if(directEdge ^ noEdge) curMid = i;
        }
    }



    int node = 1;
    while(node != 0) {
        cout << node << ' ';
        node = R[node];
    }



    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 17916kb

input:

4 4
1 2
1 3
1 4
3 4

output:

1 4 2 3 

result:

ok qwq

Test #2:

score: 0
Accepted
time: 5ms
memory: 18020kb

input:

5 0

output:

1 2 3 4 5 

result:

ok qwq

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 18000kb

input:

10 10
7 8
7 5
5 2
6 1
10 7
4 6
5 8
3 2
10 5
1 10

output:

1 5 6 2 10 

result:

wrong output format Unexpected end of file - int32 expected