Submission #124474

# Submission time Handle Problem Language Result Execution time Memory
124474 2019-07-03T11:53:32 Z DJ035 None (KOI17_civilization) C++14
100 / 100
892 ms 40068 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,par[101010],sz[101010],chk[2020][2020],day[2020][2020],dx[4]={0,0,1,-1},dy[4]={-1,1,0,0},cnt,a,b;
queue<int> qx,qy;
int f(int a){
    if(a==par[a]) return a;
    return par[a]=f(par[a]);
}
void uni(int a,int b){
    if(sz[a]>=sz[b]) par[b]=a,sz[a]+=sz[b];
    else par[a]=b,sz[b]+=sz[a];
}
main(){
    cin >> n >> m;
    for(int i=1;i<=m;i++){
        cin >> a >> b;
        par[i]=chk[a][b]=i;
        qx.push(a),qy.push(b);
    }
    if(m==1){cout << 0;return 0;}
    while(!qx.empty()){
        int x=qx.front(),y=qy.front();
        qx.pop(),qy.pop();
        for(int i=0;i<4;i++){
            int xx=x+dx[i],yy=y+dy[i];
            if(xx<1 || yy<1 || xx>n || yy>n) continue;
            if(chk[xx][yy]){
                if(day[xx][yy] <= day[x][y] && f(chk[x][y]) != f(chk[xx][yy])){
                    uni(f(chk[x][y]),f(chk[xx][yy]));
                    cnt++;
                    if(cnt == m-1){cout << day[x][y];return 0;}
                }
                continue;
            }
            qx.push(xx),qy.push(yy);
            chk[xx][yy]=chk[x][y];
            day[xx][yy]=day[x][y]+1;
        }
    }
}

Compilation message

civilization.cpp:14:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 4 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1148 KB Output is correct
8 Correct 3 ms 1272 KB Output is correct
9 Correct 3 ms 1272 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 4 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1148 KB Output is correct
8 Correct 3 ms 1272 KB Output is correct
9 Correct 3 ms 1272 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 64 ms 15808 KB Output is correct
13 Correct 50 ms 14200 KB Output is correct
14 Correct 67 ms 15216 KB Output is correct
15 Correct 44 ms 12920 KB Output is correct
16 Correct 9 ms 4220 KB Output is correct
17 Correct 259 ms 20764 KB Output is correct
18 Correct 266 ms 20636 KB Output is correct
19 Correct 254 ms 20740 KB Output is correct
20 Correct 270 ms 20800 KB Output is correct
21 Correct 269 ms 20624 KB Output is correct
22 Correct 4 ms 476 KB Output is correct
23 Correct 80 ms 16140 KB Output is correct
24 Correct 3 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 4 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1148 KB Output is correct
8 Correct 3 ms 1272 KB Output is correct
9 Correct 3 ms 1272 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 64 ms 15808 KB Output is correct
13 Correct 50 ms 14200 KB Output is correct
14 Correct 67 ms 15216 KB Output is correct
15 Correct 44 ms 12920 KB Output is correct
16 Correct 9 ms 4220 KB Output is correct
17 Correct 259 ms 20764 KB Output is correct
18 Correct 266 ms 20636 KB Output is correct
19 Correct 254 ms 20740 KB Output is correct
20 Correct 270 ms 20800 KB Output is correct
21 Correct 269 ms 20624 KB Output is correct
22 Correct 4 ms 476 KB Output is correct
23 Correct 80 ms 16140 KB Output is correct
24 Correct 150 ms 31044 KB Output is correct
25 Correct 205 ms 32040 KB Output is correct
26 Correct 130 ms 22540 KB Output is correct
27 Correct 159 ms 31360 KB Output is correct
28 Correct 97 ms 20520 KB Output is correct
29 Correct 705 ms 37272 KB Output is correct
30 Correct 590 ms 34232 KB Output is correct
31 Correct 892 ms 39864 KB Output is correct
32 Correct 856 ms 39976 KB Output is correct
33 Correct 879 ms 40068 KB Output is correct
34 Correct 205 ms 32056 KB Output is correct
35 Correct 4 ms 376 KB Output is correct
36 Correct 3 ms 1144 KB Output is correct