이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef pair<double, double> pdd;
/*
desde quando vi da ultima vez até quando vejo de novo, deixo ele em ans sozinho
*/
const int MAXN = 5e5+10;
vector<pii> e[MAXN];
vector<int> ans;
bool ve[MAXN];
int v[MAXN];
int sk[MAXN];
void dfs(int x){
while (!e[x].empty()){
pii u = e[x].back();
e[x].pop_back();
if (ve[u.second] == 1) continue;
ve[u.second] = 1;
dfs(u.first);
}
ans.push_back(x);
}
void ct(int st){
// cout, then jump
cout << ans[st];
int i = st+1;
while (i<ans.size()){
if (ans[i] == ans[st]){
cout << "\n";
break;
}
cout << " " << ans[i];
if (!sk[i]) i++;
else i += sk[i];
}
sk[st] = i-st+1;
}
int main(){
std::ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
int a, b;
for (int i=0;i<m;i++){
cin >> a >> b;
e[a].emplace_back(b, i);
e[b].emplace_back(a, i);
}
dfs(1);
reverse(ans.begin(), ans.end());
for (int i=0;i<ans.size();i++){
int x = ans[i];
if (!v[x]){
v[x] = i+1;
continue;
}
ct(v[x]-1);
for (int j=v[x];j<=i;j++) v[ans[j]] = 0;
v[x] = i+1;
}
}
컴파일 시 표준 에러 (stderr) 메시지
postmen.cpp: In function 'void ct(int)':
postmen.cpp:40:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | while (i<ans.size()){
| ~^~~~~~~~~~~
postmen.cpp: In function 'int main()':
postmen.cpp:72:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i=0;i<ans.size();i++){
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |