Submission #1535273
Source Code Expand
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <queue> #include <climits> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; #define INF INT_MAX/3 #define REP(i,n) for(int i=0;i<n;i++) int main(){ int N,M; vector<vector<int>> nodes; cin>>N>>M; nodes.resize(N); REP(i,M){ int a,b; cin>>a>>b; nodes[a-1].push_back(b-1); nodes[b-1].push_back(a-1); } vector<int> path; path.push_back(0); int opposite = nodes[0][0]; while(path.size() < N){ path.push_back(opposite); if(nodes[opposite].size() == 1)break; int i = 0; int next_node = -1; while(i < nodes[opposite].size()){ if(find(path.begin(),path.end(),nodes[opposite][i]) == path.end()){ next_node = nodes[opposite][i]; break; } i++; } if(next_node == -1)break; opposite = next_node; } cout<<path.size()<<endl; for(int i = 0; i < path.size()-1; i++)cout<<path[i] + 1<<" "; cout<<path[path.size()-1] + 1<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Hamiltonish Path |
User | Kan_0021 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1131 Byte |
Status | WA |
Exec Time | 2104 ms |
Memory | 6396 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 | 3968 KB |
subtask_1_02.txt | WA | 18 ms | 896 KB |
subtask_1_03.txt | WA | 61 ms | 3968 KB |
subtask_1_04.txt | WA | 70 ms | 3584 KB |
subtask_1_05.txt | WA | 71 ms | 3584 KB |
subtask_1_06.txt | WA | 71 ms | 3584 KB |
subtask_1_07.txt | WA | 76 ms | 5888 KB |
subtask_1_08.txt | AC | 77 ms | 5760 KB |
subtask_1_09.txt | TLE | 2104 ms | 6396 KB |
subtask_1_10.txt | AC | 22 ms | 896 KB |
subtask_1_11.txt | AC | 26 ms | 1024 KB |
subtask_1_12.txt | AC | 1 ms | 256 KB |
subtask_1_13.txt | AC | 1 ms | 256 KB |