답안 #285685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285685 2020-08-29T12:19:19 Z evpipis Simurgh (IOI17_simurgh) C++11
51 / 100
189 ms 3064 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;

const int len = 1000000;
ii edge[len];
int explore[len], vis[len], par[len];

int fin(int i){
    if (par[i] == i) return i;
    return par[i] = fin(par[i]);
}

void join(int i, int j){
    i = fin(i), j = fin(j);
    if (i == j) return;
    par[i] = j;
}

vector<int> find_roads(int N, vector<int> U, vector<int> V) {
	int n = N, m = U.size();
	for (int i = 0; i < m; i++)
        edge[i] = mp(U[i], V[i]);

    while (true){
        vector<int> temp;

        for (int i = 0; i < n; i++)
            par[i] = i;

        for (int i = 0; i < m; i++)
            if (vis[i] == 1)
                join(edge[i].fi, edge[i].se), temp.pb(i);

        int fir = n-1, sec = 0;
        for (int i = 0; i < n; i++)
            fir = min(fir, fin(i)), sec = max(sec, fin(i));

        if (fir == sec) break;

        //printf("iteration starts now\n");
        //printf("fir = %d, sec = %d\n", fir, sec);

        for (int i = 0; i < m; i++){
            if (vis[i]) continue;

            int a = fin(edge[i].fi), b = fin(edge[i].se);
            if ((a == b) || (a == fir && b == sec) || (a == sec && b == fir))
                continue;

            //printf("joining %d - %d\n", a, b);
            join(a, b), temp.pb(i);
            fir = fin(fir);
            sec = fin(sec);
        }

        int mx = 0;
        for (int i = 0; i < m; i++){
            if (vis[i] || fin(edge[i].fi) == fin(edge[i].se)){
                explore[i] = -1;
            }
            else{
                temp.pb(i);
                explore[i] = count_common_roads(temp);
                /*printf("temp asked:");
                for (auto val: temp)
                    printf(" %d", val);
                printf("\n");*/
                temp.pop_back();

                mx = max(mx, explore[i]);
            }
        }

        for (int i = 0; i < m; i++){
            if (explore[i] == -1) continue;

            if (explore[i] == mx)
                vis[i] = 1;
            else
                vis[i] = -1;
        }
    }

    vector<int> res;
    for (int i = 0; i < m; i++)
        if (vis[i] == 1)
            res.pb(i);
	return res;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:92:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   92 |     for (int i = 0; i < m; i++)
      |     ^~~
simurgh.cpp:95:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   95 |  return res;
      |  ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 404 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 0 ms 384 KB correct
12 Correct 0 ms 384 KB correct
13 Correct 1 ms 384 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 404 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 0 ms 384 KB correct
12 Correct 0 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 3 ms 384 KB correct
15 Correct 3 ms 384 KB correct
16 Correct 2 ms 384 KB correct
17 Correct 2 ms 384 KB correct
18 Correct 1 ms 384 KB correct
19 Correct 3 ms 384 KB correct
20 Correct 2 ms 384 KB correct
21 Correct 2 ms 384 KB correct
22 Correct 2 ms 384 KB correct
23 Correct 2 ms 384 KB correct
24 Correct 2 ms 384 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 2 ms 384 KB correct
27 Correct 2 ms 384 KB correct
28 Correct 2 ms 384 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 2 ms 384 KB correct
31 Correct 2 ms 416 KB correct
32 Correct 2 ms 384 KB correct
33 Correct 2 ms 308 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 404 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 0 ms 384 KB correct
12 Correct 0 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 3 ms 384 KB correct
15 Correct 3 ms 384 KB correct
16 Correct 2 ms 384 KB correct
17 Correct 2 ms 384 KB correct
18 Correct 1 ms 384 KB correct
19 Correct 3 ms 384 KB correct
20 Correct 2 ms 384 KB correct
21 Correct 2 ms 384 KB correct
22 Correct 2 ms 384 KB correct
23 Correct 2 ms 384 KB correct
24 Correct 2 ms 384 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 2 ms 384 KB correct
27 Correct 2 ms 384 KB correct
28 Correct 2 ms 384 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 2 ms 384 KB correct
31 Correct 2 ms 416 KB correct
32 Correct 2 ms 384 KB correct
33 Correct 2 ms 308 KB correct
34 Correct 181 ms 1400 KB correct
35 Correct 189 ms 1408 KB correct
36 Correct 128 ms 1024 KB correct
37 Correct 10 ms 384 KB correct
38 Correct 180 ms 1408 KB correct
39 Correct 152 ms 1280 KB correct
40 Correct 118 ms 1016 KB correct
41 Correct 21 ms 1408 KB correct
42 Correct 118 ms 1484 KB correct
43 Correct 140 ms 896 KB correct
44 Correct 121 ms 888 KB correct
45 Correct 138 ms 948 KB correct
46 Correct 105 ms 768 KB correct
47 Correct 49 ms 512 KB correct
48 Correct 8 ms 384 KB correct
49 Correct 18 ms 384 KB correct
50 Correct 51 ms 512 KB correct
51 Correct 138 ms 896 KB correct
52 Correct 120 ms 868 KB correct
53 Correct 108 ms 768 KB correct
54 Correct 146 ms 896 KB correct
55 Correct 124 ms 888 KB correct
56 Correct 118 ms 888 KB correct
57 Correct 119 ms 1016 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Incorrect 142 ms 3064 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 404 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 0 ms 384 KB correct
12 Correct 0 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 3 ms 384 KB correct
15 Correct 3 ms 384 KB correct
16 Correct 2 ms 384 KB correct
17 Correct 2 ms 384 KB correct
18 Correct 1 ms 384 KB correct
19 Correct 3 ms 384 KB correct
20 Correct 2 ms 384 KB correct
21 Correct 2 ms 384 KB correct
22 Correct 2 ms 384 KB correct
23 Correct 2 ms 384 KB correct
24 Correct 2 ms 384 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 2 ms 384 KB correct
27 Correct 2 ms 384 KB correct
28 Correct 2 ms 384 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 2 ms 384 KB correct
31 Correct 2 ms 416 KB correct
32 Correct 2 ms 384 KB correct
33 Correct 2 ms 308 KB correct
34 Correct 181 ms 1400 KB correct
35 Correct 189 ms 1408 KB correct
36 Correct 128 ms 1024 KB correct
37 Correct 10 ms 384 KB correct
38 Correct 180 ms 1408 KB correct
39 Correct 152 ms 1280 KB correct
40 Correct 118 ms 1016 KB correct
41 Correct 21 ms 1408 KB correct
42 Correct 118 ms 1484 KB correct
43 Correct 140 ms 896 KB correct
44 Correct 121 ms 888 KB correct
45 Correct 138 ms 948 KB correct
46 Correct 105 ms 768 KB correct
47 Correct 49 ms 512 KB correct
48 Correct 8 ms 384 KB correct
49 Correct 18 ms 384 KB correct
50 Correct 51 ms 512 KB correct
51 Correct 138 ms 896 KB correct
52 Correct 120 ms 868 KB correct
53 Correct 108 ms 768 KB correct
54 Correct 146 ms 896 KB correct
55 Correct 124 ms 888 KB correct
56 Correct 118 ms 888 KB correct
57 Correct 119 ms 1016 KB correct
58 Correct 0 ms 384 KB correct
59 Correct 1 ms 384 KB correct
60 Incorrect 142 ms 3064 KB WA in grader: NO
61 Halted 0 ms 0 KB -