이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define task "comseq"
#define ii pair<int,int>
#define fi first
#define se second
#define int long long
#define ll long long
#define ld double
#define mp make_pair
#define lg2 30
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define fii fi.fi
#define fis fi.se3
#define sfi se.fi
#define see se.se
#define base 29
int dx[]={0LL,0LL,1,-1,1,1,-1,-1};
int dy[]={1,-1,0LL,0LL,1,-1,1,-1};
const int maxn=1e6+1;
const int mod=1e9+7;
int n,in[maxn],out[maxn],m,vis[maxn];
vector<int>ans;
vector<ii>a[maxn];
void dfs(int u)
{
while(!a[u].empty())
{
int tmp=a[u].back().fi;
int vt=a[u].back().se;
a[u].pop_back();
if(!vis[vt]){
vis[vt]=1;
dfs(tmp);
}
}
ans.push_back(u);
}
int pos[maxn];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);}
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int u,v;
cin>>u>>v;
a[u].push_back({v,i});
a[v].push_back({u,i});
}
dfs(1);
reverse(ans.begin(),ans.end());
stack<int>s;
for(int i=0;i<ans.size();i++)
{
if(pos[ans[i]]==0)pos[ans[i]]=1;
else
{
while(true)
{
int t=s.top();s.pop();
pos[t]=0;
cout<<t<<" ";
if(t==ans[i])break;
}
cout<<'\n';
}
pos[ans[i]]=1;
s.push(ans[i]);
}
cerr <<endl<< "TIME : " << clock() * 0.001 << "s" << endl ;
}
컴파일 시 표준 에러 (stderr) 메시지
postmen.cpp: In function 'int main()':
postmen.cpp:58:18: 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]
58 | for(int i=0;i<ans.size();i++)
| ~^~~~~~~~~~~
postmen.cpp:45:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
postmen.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | freopen(task".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |