Submission #25202

# Submission time Handle Problem Language Result Execution time Memory
25202 2017-06-20T19:14:28 Z minimario Senior Postmen (BOI14_postmen) C++14
55 / 100
116 ms 17980 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define pb push_back
#define mp make_pair
#define f first
#define s second

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) FOR(i, 0, a)

const int MAX = 100005;
const int MAXN = 1000005;
const int MOD = 1000000007;
const int MAGIC = 3;

template <typename T>
std::ostream& operator<< (std::ostream& out, const std::vector<T>& v) {
  if ( !v.empty() ) {
    out << '[';
    std::copy (v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
    out << "\b\b]";
  }
  return out;
}

int e1[MAXN], e2[MAXN], banned[MAXN]; // edges, and dif the edge is banned
vi g[MAX];

void remove_edges(int u) {
    while (!g[u].empty() && banned[g[u].back()]) {
        g[u].pop_back();
    }
}

int v[MAX];
vector<vi> answer;

void chain(int u) {
    vi ord;
    int st = u;
    while (!g[st].empty()) {
        ord.pb(st);
        int e = g[st].back(); banned[e] = true;
        int from = st, to = e1[e] + e2[e] - from;
        remove_edges(from); remove_edges(to);
        st = to;
    }
    ord.pb(st);
    vi cycle, cur;
    for (int i : ord) {
        cur.pb(i);
        v[i]++;
        if (v[i] >= 2) {
            do {
                v[cur.back()]--;
                cycle.pb(cur.back());
                cur.pop_back();
            } while (cur.back() != i);
            cycle.pb(cycle[0]);
            answer.pb(cycle);
            cycle.clear();
        }
    }
    for (int i : cur) { v[i]--; }
}


int main() {
    int num = 0; // number of edge
    int n, m; scanf("%d %d", &n, &m);
    F0R(i, m) {
        int a, b; scanf("%d %d", &a, &b);
        e1[i] = a; e2[i] = b;
        g[a].pb(i); g[b].pb(i); num++;
    }
    FOR(i, 1, n+1) { chain(i); }
    for (vector<int> i : answer) { num -= i.size(); num++; }
    if (num == 0) {
        for (vector<int> i : answer) {
            FOR(moo, 1, i.size()) { printf("%d ", i[moo]); }
            printf("\n");
        }
    }
    else { printf("NIE\n"); }
}

Compilation message

postmen.cpp: In function 'int main()':
postmen.cpp:14:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(i, a, b) for (int i=a; i<b; i++)
postmen.cpp:86:17:
             FOR(moo, 1, i.size()) { printf("%d ", i[moo]); }
                 ~~~~~~~~~~~~~~~~     
postmen.cpp:86:13: note: in expansion of macro 'FOR'
             FOR(moo, 1, i.size()) { printf("%d ", i[moo]); }
             ^~~
postmen.cpp:76:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int n, m; scanf("%d %d", &n, &m);
               ~~~~~^~~~~~~~~~~~~~~~~
postmen.cpp:78:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int a, b; scanf("%d %d", &a, &b);
                   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 7 ms 2816 KB Output is correct
5 Correct 7 ms 2688 KB Output is correct
6 Correct 8 ms 2816 KB Output is correct
7 Correct 16 ms 3328 KB Output is correct
8 Correct 7 ms 2816 KB Output is correct
9 Correct 55 ms 6512 KB Output is correct
10 Correct 10 ms 2944 KB Output is correct
11 Correct 8 ms 2816 KB Output is correct
12 Correct 63 ms 6636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2688 KB Output is correct
2 Correct 8 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 8 ms 2944 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 10 ms 2816 KB Output is correct
7 Correct 13 ms 3456 KB Output is correct
8 Correct 9 ms 2816 KB Output is correct
9 Correct 45 ms 6384 KB Output is correct
10 Correct 8 ms 2944 KB Output is correct
11 Correct 9 ms 2944 KB Output is correct
12 Correct 57 ms 6640 KB Output is correct
13 Correct 101 ms 9648 KB Output is correct
14 Correct 103 ms 9112 KB Output is correct
15 Correct 83 ms 10016 KB Output is correct
16 Correct 115 ms 9736 KB Output is correct
17 Correct 116 ms 9704 KB Output is correct
18 Correct 101 ms 9264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 7 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 8 ms 2944 KB Output is correct
5 Correct 7 ms 2688 KB Output is correct
6 Correct 7 ms 2944 KB Output is correct
7 Correct 12 ms 3328 KB Output is correct
8 Correct 7 ms 2816 KB Output is correct
9 Correct 46 ms 5744 KB Output is correct
10 Correct 12 ms 2816 KB Output is correct
11 Correct 7 ms 2816 KB Output is correct
12 Correct 52 ms 6008 KB Output is correct
13 Correct 92 ms 9076 KB Output is correct
14 Correct 97 ms 8624 KB Output is correct
15 Correct 84 ms 9384 KB Output is correct
16 Correct 90 ms 9076 KB Output is correct
17 Correct 112 ms 9012 KB Output is correct
18 Correct 105 ms 8692 KB Output is correct
19 Runtime error 37 ms 17980 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Halted 0 ms 0 KB -