제출 #25202

#제출 시각아이디문제언어결과실행 시간메모리
25202minimario어르신 집배원 (BOI14_postmen)C++14
55 / 100
116 ms17980 KiB
#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"); } }

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...