백준 9372 상근이의 여행

백준 9372 상근이의 여행

의외로 굉장히 쉬웠던 문제였다. 갔던길을 또다시 갈 수 있으나 두 지점을 점프해서 갈 수는 없다 꼭 한칸씩 이동해야한다는 것이다. 제약사항이 없는 상태에서 한칸씩 이동할 수 있는 상황이고, 이때 모든 n개의 노드를 방문하는 가장 최소의 움직임은 n-1일 수 밖에 없다.

#include #include using namespace std; int t, n, m; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> t; while(t--){ cin >> n >> m; for(int i=0; i> a >> b; } cout << n-1 << endl; } return 0; }

반응형

from http://hae-ong.tistory.com/85 by ccl(A) rewrite - 2021-10-26 16:00:39