# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
25206 | 2017-06-20T19:34:57 Z | minimario | 어르신 집배원 (BOI14_postmen) | C++14 | 119 ms | 18048 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]); if (moo == (int) i.size() - 1) { printf("\n"); } else { printf(" "); } } } } else { printf("NIE\n"); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 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 | 9 ms | 2816 KB | Output is correct |
5 | Correct | 7 ms | 2792 KB | Output is correct |
6 | Correct | 8 ms | 2816 KB | Output is correct |
7 | Correct | 13 ms | 3304 KB | Output is correct |
8 | Correct | 9 ms | 2816 KB | Output is correct |
9 | Correct | 51 ms | 5848 KB | Output is correct |
10 | Correct | 9 ms | 2816 KB | Output is correct |
11 | Correct | 8 ms | 2944 KB | Output is correct |
12 | Correct | 64 ms | 6004 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 2664 KB | Output is correct |
2 | Correct | 6 ms | 2688 KB | Output is correct |
3 | Correct | 7 ms | 2688 KB | Output is correct |
4 | Correct | 10 ms | 2816 KB | Output is correct |
5 | Correct | 8 ms | 2688 KB | Output is correct |
6 | Correct | 8 ms | 2944 KB | Output is correct |
7 | Correct | 14 ms | 3328 KB | Output is correct |
8 | Correct | 7 ms | 2816 KB | Output is correct |
9 | Correct | 49 ms | 5752 KB | Output is correct |
10 | Correct | 10 ms | 2864 KB | Output is correct |
11 | Correct | 8 ms | 2816 KB | Output is correct |
12 | Correct | 54 ms | 5980 KB | Output is correct |
13 | Correct | 97 ms | 9052 KB | Output is correct |
14 | Correct | 98 ms | 8496 KB | Output is correct |
15 | Correct | 98 ms | 9452 KB | Output is correct |
16 | Correct | 98 ms | 9048 KB | Output is correct |
17 | Correct | 112 ms | 8984 KB | Output is correct |
18 | Correct | 110 ms | 8680 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 2688 KB | Output is correct |
2 | Correct | 6 ms | 2688 KB | Output is correct |
3 | Correct | 6 ms | 2740 KB | Output is correct |
4 | Correct | 7 ms | 2944 KB | Output is correct |
5 | Correct | 7 ms | 2688 KB | Output is correct |
6 | Correct | 8 ms | 2816 KB | Output is correct |
7 | Correct | 13 ms | 3328 KB | Output is correct |
8 | Correct | 8 ms | 2816 KB | Output is correct |
9 | Correct | 57 ms | 5744 KB | Output is correct |
10 | Correct | 9 ms | 2816 KB | Output is correct |
11 | Correct | 10 ms | 2816 KB | Output is correct |
12 | Correct | 64 ms | 5980 KB | Output is correct |
13 | Correct | 104 ms | 9076 KB | Output is correct |
14 | Correct | 107 ms | 8496 KB | Output is correct |
15 | Correct | 90 ms | 9504 KB | Output is correct |
16 | Correct | 104 ms | 9052 KB | Output is correct |
17 | Correct | 119 ms | 9008 KB | Output is correct |
18 | Correct | 107 ms | 8648 KB | Output is correct |
19 | Runtime error | 26 ms | 18048 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
20 | Halted | 0 ms | 0 KB | - |