이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=1e5+5;
vector<int> degree(N);
vector<vector<pair<int,int> > > graf(N);
vector<int> visited[N];
vector<vector<int> > sol;
stack<int> stk;
vector<int> vis(N);
int cnt=0;
int lim=2*1e6;
void solve(int tr)
{
cnt++;
assert(cnt<lim);
//printf("Usao za %i\n",tr);
vis[tr]++;
stk.push(tr);
if(vis[tr]==2)
{
vector<int> t;
t.pb(tr);
vis[tr]--;
stk.pop();
while(stk.top()!=tr)
{
t.pb(stk.top());
vis[stk.top()]--;
stk.pop();
}
t.pb(stk.top());
sol.pb(t);
}
for(int i=0;i<graf[tr].size();i++)
{
if(!visited[tr][i])
{
int p=graf[tr][i].first;
int j=graf[tr][i].second;
visited[tr][i]=1;
visited[p][j]=1;
degree[tr]--;
degree[p]--;
solve(p);
return;
}
}
}
void fastscan(int &number)
{
register int c;
number = 0;
c = getchar();
for (; (c>47 && c<58); c=getchar())
number = number *10 + c - 48;
}
int main()
{
/*int n=1e5,m=1e6;
//scanf("%i %i",&n,&m);
for(int i=1;i<=n;i++)
{
for(int j=0;j<10;j++){
int a=i,b=(i+j)%n+1,s=1,t=0;
if(a==b)
continue;
// printf("%i %i\n",a,b);
//scanf("%i %i %i %i",&a,&b,&s,&t);
if(s!=t)
{
graf[a].pb({b,graf[b].size()});
graf[b].pb({a,graf[a].size()-1});
visited[a].pb(0);
visited[b].pb(0);
degree[a]++;
degree[b]++;
}
}
}*/
int t=clock();
int n,m;
//scanf("%i %i",&n,&m);
fastscan(n);
fastscan(m);
for(int i=0;i<m;i++)
{
int a,b,s,t;
fastscan(a);
fastscan(b);
fastscan(s);
fastscan(t);
if(a==b)
assert(0);
//scanf("%i %i %i %i",&a,&b,&s,&t);
if(s!=t)
{
graf[a].pb({b,graf[b].size()});
graf[b].pb({a,graf[a].size()-1});
visited[a].pb(0);
visited[b].pb(0);
degree[a]++;
degree[b]++;
//printf("Dodajem iz %i u %i\n",a,b);
}
if(t-clock()>1000)
assert(0);
}
for(int i=1;i<=n;i++)
{
if(degree[i]%2==1)
{
printf("NIE\n");
return 0;
}
}
assert(t-clock()<1000);
for(int i=1;i<=n;i++)
{
while(degree[i]!=0)
{
while(stk.size())
stk.pop();
solve(i);
vis[i]--;
}
}
//printf("%i\n",cnt);
printf("%d\n",sol.size());
for(auto p:sol)
{
/*if(t-clock()>2000)
assert(0);*/
printf("%d ",p.size()-1);
for(auto d:p)
{
printf("%d ",d);
}
printf("\n");
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
smi.cpp: In function 'void solve(int)':
smi.cpp:38:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<graf[tr].size();i++)
~^~~~~~~~~~~~~~~~
smi.cpp: In function 'int main()':
smi.cpp:132:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::vector<int> >::size_type {aka long unsigned int}' [-Wformat=]
printf("%d\n",sol.size());
~~~~~~~~~~^
smi.cpp:137:32: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
printf("%d ",p.size()-1);
~~~~~~~~~~^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |