답안 #285677

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285677 2020-08-29T12:15:03 Z evpipis Simurgh (IOI17_simurgh) C++11
0 / 100
3000 ms 384 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, sec = 1;
        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 1 ms 384 KB correct
2 Execution timed out 3096 ms 384 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Execution timed out 3096 ms 384 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Execution timed out 3096 ms 384 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3096 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Execution timed out 3096 ms 384 KB Time limit exceeded
3 Halted 0 ms 0 KB -