# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
86823 | gs14004 | Teoretičar (COCI18_teoreticar) | C++17 | 7238 ms | 191060 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 500005;
int deg[MAXN], rem[MAXN], ptr[MAXN];
vector<pi> gph[MAXN];
int n, m, cnt, ret[MAXN];
pi a[MAXN];
void flush(vector<int> &V, vector<int> &E){
for(auto &i : V){
deg[i] = ptr[i] = 0;
gph[i].clear();
}
for(auto &i : E) rem[i] = 0;
}
void dfs(int x, int c, vector<int> &l, vector<int> &r){
while(ptr[x] < gph[x].size()){
auto e = gph[x][ptr[x]];
ptr[x]++;
if(!rem[e.first]){
rem[e.first] = 1;
if(c & 1) r.push_back(e.first);
else l.push_back(e.first);
deg[a[e.first].first]--;
deg[a[e.first].second]--;
dfs(e.second, c + 1, l, r);
break;
}
}
}
void assign(vector<int> edges){
bool not_base = 0;
vector<int> vlist;
for(auto &i : edges){
int s = a[i].first;
int e = a[i].second;
if(!deg[s]) vlist.push_back(s);
deg[s]++;
if(!deg[e]) vlist.push_back(e);
deg[e]++;
if(deg[s] > 1 || deg[e] > 1) not_base = 1;
gph[s].emplace_back(i, e);
gph[e].emplace_back(i, s);
}
if(!not_base){
cnt++;
for(auto &i : edges) ret[i] = cnt;
flush(vlist, edges);
return;
}
vector<int> l, r;
for(auto &i : vlist){
if(deg[i] & 1){
dfs(i, 0, l, r);
}
}
for(auto &i : vlist){
while(deg[i]){
dfs(i, 0, l, r);
}
}
flush(vlist, edges);
assign(l);
assign(r);
}
int main(){
int k;
scanf("%d %d %d",&n,&k,&m);
vector<int> v;
for(int i=0; i<m; i++){
scanf("%d %d",&a[i].first,&a[i].second);
a[i].second += n;
v.push_back(i);
}
assign(v);
printf("%d\n", cnt);
for(int i=0; i<m; i++){
printf("%d\n", ret[i]);
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |