답안 #441386

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441386 2021-07-05T06:33:42 Z daniel920712 분수 공원 (IOI21_parks) C++17
0 / 100
0 ms 204 KB
#include "parks.h"
#include <map>
#include <utility>
#include <queue>
using namespace std;
map < pair < int , int > , int > all,con;
map < pair < int , int > , pair < int , int > > road;
vector < int > u,v,a,b;
queue < pair < int , int > > BFS;
int Father[200005];
int Find(int here)
{
    if(Father[here]==here) return here;
    Father[here]=Find(Father[here]);
    return Father[here];
}
int construct_roads(vector < int > x, vector < int > y)
{
    int N=x.size(),i,t,aa,bb,ok=1,xx,yy;
    for(i=0;i<N;i++)
    {
        all[make_pair(x[i],y[i])]=i;
        Father[i]=i;
    }
    for(i=0;i<N;i++)
    {
        if(all.find(make_pair(x[i],y[i]+2))!=all.end())
        {
            t=all[make_pair(x[i],y[i]+2)];
            road[make_pair(x[i],y[i]+1)]=make_pair(i,t);
            con[make_pair(x[i]+1,y[i]+1)]++;
            con[make_pair(x[i]-1,y[i]+1)]++;

            aa=Find(i);
            bb=Find(t);
            if(aa!=bb) Father[aa]=bb;

        }
        if(all.find(make_pair(x[i]+2,y[i]))!=all.end())
        {
            t=all[make_pair(x[i]+2,y[i])];
            road[make_pair(x[i]+1,y[i])]=make_pair(i,t);
            con[make_pair(x[i]+1,y[i]+1)]++;
            con[make_pair(x[i]+1,y[i]-1)]++;
            aa=Find(i);
            bb=Find(t);
            if(aa!=bb) Father[aa]=bb;
        }
    }
    for(auto i:con) if(i.second==1) BFS.push(i.first);
    while(!BFS.empty())
    {
        xx=BFS.front().first;
        yy=BFS.front().second;
        BFS.pop();
        if(con[make_pair(xx,yy)]==0) continue;
        if(road.find(make_pair(xx+1,yy))!=road.end()) aa=xx+1,bb=yy;
        if(road.find(make_pair(xx-1,yy))!=road.end()) aa=xx-1,bb=yy;
        if(road.find(make_pair(xx,yy+1))!=road.end()) aa=xx,bb=yy+1;
        if(road.find(make_pair(xx,yy-1))!=road.end()) aa=xx,bb=yy-1;
        u.push_back(road[make_pair(aa,bb)].first);
        v.push_back(road[make_pair(aa,bb)].second);
        road.erase(make_pair(aa,bb));
        if(aa%2==0)
        {
            con[make_pair(aa-1,bb)]--;
            con[make_pair(aa+1,bb)]--;

            if(con[make_pair(aa-1,bb)]==1) BFS.push(make_pair(aa-1,bb));
            if(con[make_pair(aa+1,bb)]==1) BFS.push(make_pair(aa+1,bb));
        }
        else
        {
            con[make_pair(aa,bb-1)]--;
            con[make_pair(aa,bb+1)]--;

            if(con[make_pair(aa,bb-1)]==1) BFS.push(make_pair(aa,bb-1));
            if(con[make_pair(aa,bb+1)]==1) BFS.push(make_pair(aa,bb+1));
        }

    }

    t=Find(0);
    for(i=0;i<N;i++)  if(t!=Find(i)) ok=0;
    if(!road.empty()) ok=0;
    if(ok) build(u,v,a,b);
    return ok;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:75:32: warning: 'bb' may be used uninitialized in this function [-Wmaybe-uninitialized]
   75 |             con[make_pair(aa,bb+1)]--;
      |                              ~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Wrong answer detected in grader
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Wrong answer detected in grader
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Wrong answer detected in grader
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Wrong answer detected in grader
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Wrong answer detected in grader
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Wrong answer detected in grader
3 Halted 0 ms 0 KB -