이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sp <<' '<<
#define pb push_back
#define FOR(i,a) for(int i=0;i<(a);i++)
#define FORE(i,a,b) for(int i=(a);i<(b);i++)
#define cont(a) for(auto el:a) cout<<el<<' '; cout<<endl;
#define contp(a) for(auto el:a) cout<<el.fi<<'-'<<el.se<<' ';cout<<endl;
#define DEBUG(x) cout<<#x sp ":" sp x<<endl;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef long long ll;
#define endl '\n'
#define mid (l+r)/2
#define topla(x,y) ((x%MOD)+(y%MOD))%MOD
#define carp(x,y) ((x%MOD)*(y%+MOD))%MOD
const int MAXN=5e5+5;
const int INF=1e16;
int n,m;
vii adj[MAXN];
bool vis[MAXN];
vi cev;
void dfs(int nd){
while(!adj[nd].empty()){
auto el=adj[nd].back();
int kom=el.fi;
int yol=el.se;
adj[nd].pop_back();
if(vis[yol]) continue;
vis[yol]=true;
dfs(kom);
}
cev.pb(nd);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
FOR(i,m){
int a,b;
cin>>a>>b;
adj[a].pb({b,i+1});
adj[b].pb({a,i+1});
}
//find eulerian circuit
dfs(1);
vi st;
FORE(i,1,n+1) vis[i]=false;
vector<vi> ans;
vi temp;
FOR(i,cev.size()){
int kom=cev[i];
if(vis[kom]){
int el;
do{
el=st.back();
st.pop_back();
temp.pb(el);
vis[el]=false;
}while(el!=kom);
ans.pb(temp);
temp.clear();
}
st.pb(kom);
vis[kom]=true;
}
st.pop_back();
if(!st.empty()) ans.pb(st);
for(auto el:ans){
cont(el);
}
}
컴파일 시 표준 에러 (stderr) 메시지
postmen.cpp: In function 'int main()':
postmen.cpp:12:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | #define FOR(i,a) for(int i=0;i<(a);i++)
| ^
postmen.cpp:79:5: note: in expansion of macro 'FOR'
79 | FOR(i,cev.size()){
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |