답안 #685850

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685850 2023-01-25T02:11:01 Z Sunbae 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
186 ms 27888 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
vector<int>parent;
vector<int>Size;
int findUpar(int node){
    if(node == parent[node]) return node;
    return parent[node] = findUpar(parent[node]);
}
void Union(int u, int v){
    int pu = findUpar(u), pv = findUpar(v);
    if(pu == pv) return;
    if(Size[pu] > Size[pv]){
        parent[pv] = pu; Size[pu] += Size[pv];
    }else{
        parent[pu] = pv; Size[pv] += Size[pu];
    }
}
bool detectCycle(int src, vector<int> Adj[], vector<bool>&visited, int n){
    visited[src] = true;
    queue<pair<int,int>>q;
    q.push({src, -1});
    while(!q.empty()){
        int node = q.front().first;
        int par = q.front().second;
        q.pop();
        for(int adjNode: Adj[node]){
            if(!visited[adjNode]){
                visited[adjNode] = true;
                q.push({adjNode, node});
            }else if(par != adjNode){
                return true;
            }
        }
    }
    return false;
}
int construct(vector<vector<int>>p){
    vector<pair<int,int>>zero, two;
    int n = p.size(); Size.resize(n); parent.resize(n);
    for(int i = 0; i<n; i++) Size[i] = 1, parent[i] = i;
    vector<vector<int>>adj(n, vector<int>(n, 0));
    for(int i = 0; i<n; i++){
        for(int j = 0; j<n; j++){
            if(p[i][j] == 0){
                zero.push_back({i, j});
            }else if(p[i][j] == 1){
                Union(i, j);
            }else if(p[i][j] == 2){
                two.push_back({i, j});
            }else if(p[i][j] == 3){
                return 0;
            }
        }
    }
    //mark 1
    for(int i = 0; i<n; i++){
        int pi = findUpar(i);
        if(i != pi){
            adj[i][pi] = 1; adj[pi][i] = 1;
        }
    }
    //mark 2
    vector<int>Adj[n];
    for(pair<int,int> it: two){
        int u = it.first, v = it.second;
        int pu = findUpar(u), pv = findUpar(v);
        if(pu == pv) return 0;
        adj[pu][pv] = 1; adj[pv][pu] = 1;
        Adj[pu].push_back(pv); Adj[pv].push_back(pu);
    }
    //check cycle
    vector<bool>visited(n, false);
    int cnt = 0;
    for(int i = 0; i<n; i++){
        if(!visited[i]){
            bool cycle = detectCycle(i, Adj, visited, n);
            if(cycle){
                ++cnt;
            }
        }
    }
    if(cnt >= 2) return 0;
    //Union 2
    for(pair<int,int> it: two){
        Union(it.first, it.second);
    }
    //check 0
    for(pair<int,int> it: zero){
        int pu = findUpar(it.first), pv = findUpar(it.second);
        if(pu == pv) return 0;
    }
    build(adj); return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 160 ms 22020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 160 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1364 KB Output is correct
13 Correct 184 ms 27884 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 220 KB Output is correct
16 Correct 4 ms 1108 KB Output is correct
17 Correct 86 ms 16380 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 7168 KB Output is correct
21 Correct 175 ms 27064 KB Output is correct
22 Correct 182 ms 27872 KB Output is correct
23 Correct 177 ms 23936 KB Output is correct
24 Correct 180 ms 27812 KB Output is correct
25 Correct 80 ms 20484 KB Output is correct
26 Correct 80 ms 20488 KB Output is correct
27 Correct 178 ms 23932 KB Output is correct
28 Correct 177 ms 27884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 49 ms 7164 KB Output is correct
5 Correct 184 ms 27060 KB Output is correct
6 Correct 186 ms 27888 KB Output is correct
7 Correct 177 ms 23996 KB Output is correct
8 Incorrect 0 ms 212 KB Too many ways to get from 0 to 2, should be 2 found no less than 3
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 160 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1364 KB Output is correct
13 Correct 184 ms 27884 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 220 KB Output is correct
16 Correct 4 ms 1108 KB Output is correct
17 Correct 86 ms 16380 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 7168 KB Output is correct
21 Correct 175 ms 27064 KB Output is correct
22 Correct 182 ms 27872 KB Output is correct
23 Correct 177 ms 23936 KB Output is correct
24 Correct 180 ms 27812 KB Output is correct
25 Correct 80 ms 20484 KB Output is correct
26 Correct 80 ms 20488 KB Output is correct
27 Correct 178 ms 23932 KB Output is correct
28 Correct 177 ms 27884 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 160 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1364 KB Output is correct
13 Correct 184 ms 27884 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 220 KB Output is correct
16 Correct 4 ms 1108 KB Output is correct
17 Correct 86 ms 16380 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 7168 KB Output is correct
21 Correct 175 ms 27064 KB Output is correct
22 Correct 182 ms 27872 KB Output is correct
23 Correct 177 ms 23936 KB Output is correct
24 Correct 180 ms 27812 KB Output is correct
25 Correct 80 ms 20484 KB Output is correct
26 Correct 80 ms 20488 KB Output is correct
27 Correct 178 ms 23932 KB Output is correct
28 Correct 177 ms 27884 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -