Submission #97098

# Submission time Handle Problem Language Result Execution time Memory
97098 2019-02-13T20:49:23 Z dalgerok Senior Postmen (BOI14_postmen) C++14
0 / 100
13 ms 12544 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 5e5 + 5;


int n, m, x[N], y[N], a[3 * N], sz;
vector < int > g[N];
bool used[N];
vector < int > q;


void dfs(int v){
    while(!g[v].empty()){
        int num = g[v].back();
        g[v].pop_back();
        if(used[num]){
            continue;
        }
        used[num] = true;
        int to = (x[num] ^ v ^ y[num]);
        dfs(to);
    }
    a[++sz] = v;
}

inline void read(int &x){
    x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){
        c = getchar();
    }
    while('0' <= c && c <= '9'){
        x = x * 10 + c - '0';
        c = getchar();
    }
}
inline void print(int x){
    int len = 0;
    while(x % 10 == 0){
        len += 1;
        x /= 10;
    }
    int y = 0;
    while(x){
        y = y * 10 + x % 10;
        x /= 10;
    }
    while(y){
        putchar('0' + y % 10);
        y /= 10;
    }
    while(len--){
        putchar('0');
    }
}

int main(){
    read(n);
    read(m);
    for(int i = 1; i <= m; i++){
        read(x[i]);
        read(y[i]);
        g[x[i]].push_back(i);
        g[y[i]].push_back(i);
    }
    dfs(1);
    memset(used, 0, sizeof(used));
    vector < int > s;
    for(int i = 1; i <= sz; i++){
        int it = a[i];
        if(!used[it]){
            used[it] = true;
            s.push_back(it);
        }
        else{
            while(s.back() != it){
                print(s.back());
                putchar('\n');
                used[s.back()] = false;
                s.pop_back();
            }
            print(it);
            putchar('\n');
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 12544 KB Edge does not exist or used 2, 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 12544 KB Edge does not exist or used 2, 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 12544 KB Edge does not exist or used 2, 0
2 Halted 0 ms 0 KB -