Submission #1222173
Source Code Expand
#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <string> #include <bitset> #include <cstdio> #include <limits> #include <vector> #include <climits> #include <cstring> #include <cstdlib> #include <fstream> #include <numeric> #include <sstream> #include <cassert> #include <iomanip> #include <iostream> #include <algorithm> #include <unordered_set> #include <unordered_map> using namespace std; #define f first #define s second #define pb push_back #define pp pop_back #define mp make_pair #define ll long long #define ld long double #define ull unsigned long long #define PI pair < int, int > const int N = 1e5 + 123; const int M = 123; const ld Pi = acos(-1); const ll Inf = 1e18; const int inf = 1e9; const int mod = 1000200013; const int Sz = 501; void add(int &a, int b) { a += b; if (a >= mod) a -= mod; } int mult(int a, int b) { return 1ll * a * b % mod; } int sum(int a, int b) { add(a, b); return a; } int n, m; vector < int > g[N], l, r; bool in[N]; int main() { #ifdef wws freopen("in", "r", stdin); // freopen("out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin >> n >> m; int s, t; for (int i = 1, u, v;i <= m;i++) { cin >> u >> v; g[u].pb(v); g[v].pb(u); s = u, t = v; } bool ch = 1; in[s] = in[t] = 1; l.pb(s); r.pb(t); while(ch) { ch = 0; // cout << s << " " << t << endl; for (auto x : g[s]) { if (!in[x]) { l.pb(x); s = x; ch = 1; break; } } in[s] = 1; for (auto x : g[t]) { if (!in[x]) { r.pb(x); t = x; ch = 1; break; } } in[t] = 1; } cout << (int)l.size() + r.size() << endl; for (int i = l.size() - 1;i >= 0;i--) cout << l[i] << " "; for (int i = 0;i < r.size();i++) cout << r[i] << " "; cout << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Hamiltonish Path |
User | SmallBoy |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 2039 Byte |
Status | AC |
Exec Time | 46 ms |
Memory | 7036 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 2 ms | 2560 KB |
sample_02.txt | AC | 2 ms | 2560 KB |
sample_03.txt | AC | 2 ms | 2560 KB |
subtask_1_01.txt | AC | 31 ms | 4864 KB |
subtask_1_02.txt | AC | 9 ms | 3072 KB |
subtask_1_03.txt | AC | 27 ms | 4864 KB |
subtask_1_04.txt | AC | 32 ms | 4736 KB |
subtask_1_05.txt | AC | 31 ms | 4736 KB |
subtask_1_06.txt | AC | 32 ms | 4736 KB |
subtask_1_07.txt | AC | 33 ms | 5888 KB |
subtask_1_08.txt | AC | 34 ms | 5760 KB |
subtask_1_09.txt | AC | 46 ms | 7036 KB |
subtask_1_10.txt | AC | 10 ms | 3328 KB |
subtask_1_11.txt | AC | 12 ms | 3328 KB |
subtask_1_12.txt | AC | 2 ms | 2560 KB |
subtask_1_13.txt | AC | 2 ms | 2560 KB |