답안 #426934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
426934 2021-06-14T10:57:45 Z Runtime_error_ Simurgh (IOI17_simurgh) C++14
0 / 100
4 ms 5000 KB
#include "simurgh.h"
#include <bits/stdc++.h>
#define pi pair<int,int>
#define pb push_back
using namespace std;
const int inf = 1e5+9;
vector<int> cur,adj[inf],cp[inf],ask,ret;
int n,m,u[inf],v[inf],par[inf];
set<int> rets;

int root(int x){
    if(par[x] == x)
        return x;
    return par[x] = root(par[x]);
}

bool join(int x,int y){
    x = root(x);
    y = root(y);
    if(x == y)
        return 0;
    if(rand()%2)
        swap(x,y);
    par[x] = y;
    return 1;
}

vector<int> find_roads(int N, vector<int> U, vector<int> V) {

    n = N;
    m = U.size();
    for(int i=0;i<m;i++)
        u[i] = U[i],v[i] = V[i],
        adj[u[i]].pb(v[i]),adj[v[i]].pb(u[i]);

    for(int x=0;x<n;x++){
        ask.clear();
        set<int> roots;
        for(int i=0;i<n;i++)
            par[i] = i,cp[i].clear();
        for(int i=0;i<m;i++)
            if(u[i] != x && v[i] != x && join(u[i],v[i]))
                ask.pb(i);
        for(int i=0;i<m;i++){
            if(u[i] != x && v[i] != x)
                continue;
            int y = (u[i] ==x?v[i]:u[i]);
            y = root(y);
            roots.insert(y);
            cp[y].pb(i);
        }
        for(auto rt:roots){
            for(auto ort:roots)
                if(rt != ort)
                    ask.pb(cp[ort][0]);
            pi ans= pi(0,0);
            for(auto o:cp[rt]){
                ask.pb(o);
                ans = max(ans,pi(count_common_roads(ask),o));
                ask.pop_back();
            }
            for(auto ort:roots)
                if(rt != ort)
                    ask.pop_back();
           rets.insert(ans.second);
        }
    }
    for(auto o:rets)
        ret.pb(o);
    assert(count_common_roads(ret) == n-1);
    return ret;
}
/*
4 6
0 1
0 2
0 3
1 2
1 3
2 3
0 4 5
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB correct
2 Correct 4 ms 5000 KB correct
3 Incorrect 4 ms 4940 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB correct
2 Correct 4 ms 5000 KB correct
3 Incorrect 4 ms 4940 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB correct
2 Correct 4 ms 5000 KB correct
3 Incorrect 4 ms 4940 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB correct
2 Incorrect 4 ms 4940 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB correct
2 Correct 4 ms 5000 KB correct
3 Incorrect 4 ms 4940 KB WA in grader: NO
4 Halted 0 ms 0 KB -