답안 #1004614

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1004614 2024-06-21T10:41:14 Z spensa 슈퍼트리 잇기 (IOI20_supertrees) C++14
0 / 100
1 ms 348 KB
#include "supertrees.h"
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;

int construct(std::vector<std::vector<int>> p) {
    //subtask 3: mini cycles, but as connected components
	int n = p.size();
    vector<vector<int>> ans(n, vector<int> (n));  

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            ans[i][j] = 0;
        }
    }

    map<int, vector<int>> cc;
    vector<int> flags;
    flags.push_back(0);
    cc[0].push_back(0);
    for(int i=1; i<n; i++){
        int tmp = 0;
        for(int j: flags){
            if(p[i][j]==0) continue;
            if(i==j) continue;
            ans[i][j] = 1;
            ans[j][i] = 1;
            cc[j].push_back(i);
            tmp++;
            // break;
        }
        if(tmp>=2) return 0;
        if(tmp==0){
            flags.push_back(i);
            cc[i].push_back(i);
        }
    }

    for(auto i: cc){
        // for(int j: i.second) cout<<j<<" ";
        // cout<<"\n";
        int sz = i.second.size();
        if(sz<3) continue;
        ans[i.second[sz-1]][i.second[sz-2]] = 1;
        ans[i.second[sz-2]][i.second[sz-1]] = 1;
    
    //     cout<<i.second[-1]<<"!!"<<i.second[-2]<<"\n";
    //     ans[i.second[-1]][i.second[-2]] = 1;
    //     ans[i.second[-2]][i.second[-1]] = 1;
    }

    set<pair<int,int>> act;
    for(auto i: cc){
        // cout<<"i.first="<<i.first<<"\n";
        for(int j: i.second){
            for(int k: i.second){
                act.insert(make_pair(j, k));
                act.insert(make_pair(k, j));
            }
        }
    }

    // for(auto i: act) cout<<i.first<<" "<<i.second<<"\n";
    // cout<<"\n";

    // sort(act.begin(), act.end());
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            // cout<<"here";
            if(i==j) continue;
            if(p[i][j]==0){
                if(act.count({i,j})==1) return 0;
            }
            else{
                if(act.count({i,j})==0) return 0;
            }
        }
    }

    build(ans);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Too many ways to get from 1 to 4, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -