Submission #1866659
Source Code Expand
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <climits> #define rep(i, m, n) for(int i=int(m);i<int(n);i++) #define EACH(i, c) for (auto &(i): c) #define all(c) begin(c),end(c) #define EXIST(s, e) ((s).find(e)!=(s).end()) #define SORT(c) sort(begin(c),end(c)) #define pb emplace_back #define MP make_pair #define SZ(a) int((a).size()) //#define LOCAL 0 //#ifdef LOCAL //#define DEBUG(s) cout << (s) << endl //#define dump(x) cerr << #x << " = " << (x) << endl //#define BR cout << endl; //#else //#define DEBUG(s) do{}while(0) //#define dump(x) do{}while(0) //#define BR //#endif //改造 typedef long long int ll; using namespace std; #define INF (1 << 20) #define INFl (ll)5e15 #define DEBUG 0 //デバッグする時1にしてね #define dump(x) cerr << #x << " = " << (x) << endl //ここから編集する struct edge{int from;int to;}; int main() { int N,M; cin >> N >> M; vector<vector<edge> > v(N); vector<bool> used(N,false); rep(i,0,M){ int A,B; cin >> A >> B; A--;B--; edge e{A,B}; v[A].push_back(e); swap(e.from,e.to); v[B].push_back(e); } vector<int> path; for(int i = 0; i < v.size(); i++){ if(v[i].size() > 0){ path.push_back(i); path.push_back(v[i][0].to); used[i] = true; used[v[i][0].to] = true; break; } } while(true){ bool contFlag = false; for(int i = 0; i < v[path[path.size()-1]].size(); i++){ int kouho = v[path[path.size()-1]][i].to; if(!used[kouho]){ path.push_back(kouho); used[kouho] = true; contFlag = true; } } if(!contFlag){ break; } } cout << path.size() << endl; rep(i,0,path.size()){ cout << path[i]+1; if(i != path.size()-1) cout << " "; else cout << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Hamiltonish Path |
User | homesentinel |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2646 Byte |
Status | WA |
Exec Time | 83 ms |
Memory | 6648 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | WA | 1 ms | 256 KB |
sample_02.txt | AC | 1 ms | 256 KB |
sample_03.txt | WA | 1 ms | 256 KB |
subtask_1_01.txt | WA | 67 ms | 4864 KB |
subtask_1_02.txt | WA | 17 ms | 1152 KB |
subtask_1_03.txt | WA | 61 ms | 4608 KB |
subtask_1_04.txt | WA | 71 ms | 4608 KB |
subtask_1_05.txt | WA | 71 ms | 4608 KB |
subtask_1_06.txt | WA | 71 ms | 4608 KB |
subtask_1_07.txt | WA | 73 ms | 6400 KB |
subtask_1_08.txt | AC | 73 ms | 6272 KB |
subtask_1_09.txt | WA | 83 ms | 6648 KB |
subtask_1_10.txt | AC | 22 ms | 1664 KB |
subtask_1_11.txt | AC | 26 ms | 1792 KB |
subtask_1_12.txt | AC | 1 ms | 256 KB |
subtask_1_13.txt | AC | 1 ms | 256 KB |