답안 #441389

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441389 2021-07-05T06:37:18 Z daniel920712 분수 공원 (IOI21_parks) C++17
15 / 100
1521 ms 70340 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);
        a.push_back(xx);
        b.push_back(yy);
        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:77:32: warning: 'bb' may be used uninitialized in this function [-Wmaybe-uninitialized]
   77 |             con[make_pair(aa,bb+1)]--;
      |                              ~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 482 ms 33160 KB Output is correct
10 Correct 29 ms 3908 KB Output is correct
11 Correct 176 ms 18804 KB Output is correct
12 Correct 44 ms 5552 KB Output is correct
13 Correct 135 ms 14208 KB Output is correct
14 Correct 2 ms 588 KB Output is correct
15 Correct 5 ms 844 KB Output is correct
16 Correct 535 ms 33132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 482 ms 33160 KB Output is correct
10 Correct 29 ms 3908 KB Output is correct
11 Correct 176 ms 18804 KB Output is correct
12 Correct 44 ms 5552 KB Output is correct
13 Correct 135 ms 14208 KB Output is correct
14 Correct 2 ms 588 KB Output is correct
15 Correct 5 ms 844 KB Output is correct
16 Correct 535 ms 33132 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1521 ms 70340 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 4 ms 716 KB Output is correct
26 Correct 9 ms 1212 KB Output is correct
27 Correct 12 ms 1532 KB Output is correct
28 Correct 489 ms 28360 KB Output is correct
29 Correct 824 ms 42328 KB Output is correct
30 Correct 1124 ms 56464 KB Output is correct
31 Correct 1480 ms 70300 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 5 ms 716 KB Output is correct
44 Correct 7 ms 1012 KB Output is correct
45 Correct 499 ms 28992 KB Output is correct
46 Correct 796 ms 41828 KB Output is correct
47 Correct 800 ms 41760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 482 ms 33160 KB Output is correct
10 Correct 29 ms 3908 KB Output is correct
11 Correct 176 ms 18804 KB Output is correct
12 Correct 44 ms 5552 KB Output is correct
13 Correct 135 ms 14208 KB Output is correct
14 Correct 2 ms 588 KB Output is correct
15 Correct 5 ms 844 KB Output is correct
16 Correct 535 ms 33132 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1521 ms 70340 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 4 ms 716 KB Output is correct
26 Correct 9 ms 1212 KB Output is correct
27 Correct 12 ms 1532 KB Output is correct
28 Correct 489 ms 28360 KB Output is correct
29 Correct 824 ms 42328 KB Output is correct
30 Correct 1124 ms 56464 KB Output is correct
31 Correct 1480 ms 70300 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 5 ms 716 KB Output is correct
44 Correct 7 ms 1012 KB Output is correct
45 Correct 499 ms 28992 KB Output is correct
46 Correct 796 ms 41828 KB Output is correct
47 Correct 800 ms 41760 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Incorrect 0 ms 204 KB Given structure is not connected: There is no path between vertices 0 and 1
52 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 482 ms 33160 KB Output is correct
10 Correct 29 ms 3908 KB Output is correct
11 Correct 176 ms 18804 KB Output is correct
12 Correct 44 ms 5552 KB Output is correct
13 Correct 135 ms 14208 KB Output is correct
14 Correct 2 ms 588 KB Output is correct
15 Correct 5 ms 844 KB Output is correct
16 Correct 535 ms 33132 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1039 ms 51768 KB Output is correct
21 Correct 1164 ms 51600 KB Output is correct
22 Correct 1065 ms 51648 KB Output is correct
23 Correct 900 ms 56452 KB Output is correct
24 Correct 341 ms 16832 KB Output is correct
25 Correct 1105 ms 60744 KB Output is correct
26 Correct 1079 ms 60728 KB Output is correct
27 Correct 1172 ms 67116 KB Output is correct
28 Correct 1153 ms 67108 KB Output is correct
29 Correct 1203 ms 66604 KB Output is correct
30 Correct 1204 ms 66604 KB Output is correct
31 Correct 0 ms 280 KB Output is correct
32 Incorrect 51 ms 4476 KB Given structure is not connected: There is no path between vertices 0 and 1
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 482 ms 33160 KB Output is correct
10 Correct 29 ms 3908 KB Output is correct
11 Correct 176 ms 18804 KB Output is correct
12 Correct 44 ms 5552 KB Output is correct
13 Correct 135 ms 14208 KB Output is correct
14 Correct 2 ms 588 KB Output is correct
15 Correct 5 ms 844 KB Output is correct
16 Correct 535 ms 33132 KB Output is correct
17 Correct 1095 ms 67076 KB Output is correct
18 Incorrect 1113 ms 67276 KB Given structure is not connected: There is no path between vertices 0 and 4
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 482 ms 33160 KB Output is correct
10 Correct 29 ms 3908 KB Output is correct
11 Correct 176 ms 18804 KB Output is correct
12 Correct 44 ms 5552 KB Output is correct
13 Correct 135 ms 14208 KB Output is correct
14 Correct 2 ms 588 KB Output is correct
15 Correct 5 ms 844 KB Output is correct
16 Correct 535 ms 33132 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1521 ms 70340 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 4 ms 716 KB Output is correct
26 Correct 9 ms 1212 KB Output is correct
27 Correct 12 ms 1532 KB Output is correct
28 Correct 489 ms 28360 KB Output is correct
29 Correct 824 ms 42328 KB Output is correct
30 Correct 1124 ms 56464 KB Output is correct
31 Correct 1480 ms 70300 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 5 ms 716 KB Output is correct
44 Correct 7 ms 1012 KB Output is correct
45 Correct 499 ms 28992 KB Output is correct
46 Correct 796 ms 41828 KB Output is correct
47 Correct 800 ms 41760 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Incorrect 0 ms 204 KB Given structure is not connected: There is no path between vertices 0 and 1
52 Halted 0 ms 0 KB -