-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodeforces 1144f.cpp
168 lines (128 loc) · 2.94 KB
/
codeforces 1144f.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <bits/stdc++.h>
#define MAX 2000005
using namespace std;
vector<int> graph[MAX];
int visited[MAX],color[MAX];
void addEdge(int v,int w)
{
graph[v].push_back(w);
graph[w].push_back(v);
}
//->모서리 추가하는 함수.
bool bipartite(int src)
{
memset(color,0,sizeof(color));
memset(visited,0,sizeof(visited));
color[src]=1;
visited[src]=1;
queue<int> q;
q.push(src);
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=0;i<graph[u].size();i++)
{
int v=graph[u][i];
if(color[u]==1)
{
if(color[v]==1)return false;
else color[v]=2;
}
if(color[u]==2)
{
if(color[v]==2)return false;
else color[v]=1;
}
if(!visited[v]){visited[v]=1;q.push(v);}
}
}
return true;
//}
}
//->모서리를 만들수 있는지의 여부와 그외에 잡다한 알고리즘
int main()
{
/*
6개의 숫자 5개의 모서리
입력
6 5
1 5
2 1
1 4
3 1
6 1
출력
YES
10100
구현해야될것들
2가지의 경로가 안나오면 no
이진수출력 과정
맨처음엔 무조건1로 시작
두번째 라인에서 모서리부분이 첫스타트 라인으로 되돌아오면 0
a[i][m]==a[i+1][m+1]
a[i+1][m]==a[i+1][m+1]
print 0
a[i][m]!=a[i+1][m+1]
print 1
런타임 에러 뭐야아아아아아아앙 ㅠ.ㅠ 21년 2월8일 에러사항
*/
int n,m;
//int d=2;
cin>>n>>m;
//int a[m][d];
vector<pair<int,int>>vec;
for(int i=1;i<=m;i++)
{
int u,v;
cin>>u>>v;
addEdge(u,v);
vec.push_back({u,v});
}
//->모서리를 생성하고 벡터에 u,v값을 집어넣은 과정
if(!bipartite(1))cout<<"NO"<<endl;
else
{
cout<<"YES"<<endl;
for(int i=0;i<vec.size();i++)
{
if(color[vec[i].first]==1)cout<<"1";
else cout<<"0";
}
}
//->모서리를 만들수 있는지 판별하고 만들수 있을시 u,v값에 따른 이진수 출력 과정
/*if(m<2)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
}*/
/*for(int i=0;i<m;i++)
{
for(int j=0;j<d;j++)
{
if(a[i][j]==a[i+1][j+1]||a[i+1][j]==a[i+1][j+1])
{
cout<<1;
break;
}
else
{
cout<<0;
break;
}
}
}*/
//for()
/*if(m<2)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
}*/
return 0;
}