# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1049885 | 2024-08-09T05:54:34 Z | mychecksedad | 슈퍼트리 잇기 (IOI20_supertrees) | C++17 | 1 ms | 348 KB |
#include "supertrees.h" #include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define vi vector<int> struct Dsu{ vector<int> p, s; Dsu(int n){ p.resize(n+1); s.resize(n+1,1); for(int i = 1; i <= n; ++i ) p[i]=i; } int find(int v){ if(p[v] == v)return v; return p[v]=find(p[v]); } void merge(int a, int b){ a = find(a); b = find(b); if(a != b){ if(s[a]>s[b]) swap(a,b); p[a] = b; s[b] += s[a]; } } }; vector<vector<int>> P; bool solve(vector<int> v, vector<vector<int>> &ans){ if(v.empty()) return 1; for(int u: v){ for(int x: v){ if(P[u][x] == 0 || P[u][x] == 3){ return 0; } } } vector<int> cycle; vector<vector<int>> onepiece; for(int i: v){ bool fulltwo = 1; for(int j: v){ if(i == j) continue; if(P[i][j] == 1){ fulltwo = 0; onepiece.pb(vector<int>{i, j}); // for(int k = 0; k < n; ++k){ // } } } if(fulltwo) cycle.pb(i); } // for(auto v: onepiece){ // for(int j = 0; j + 1 < v.size(); ++j){ // ans[v[j]][v[j + 1]] = ans[v[j + 1]][v[j]] = 1; // } // cycle.pb(v[0]); // } if(cycle.size() == 1) return 1; for(int i = 0; i < cycle.size(); ++i){ ans[cycle[i]][cycle[(i + 1) % cycle.size()]] = ans[cycle[(i + 1) % cycle.size()]][cycle[i]] = 1; } return 1; } int construct(std::vector<std::vector<int>> p) { int n = p.size(); P = p; vector<vector<int>> answer(n, vector<int>(n)); Dsu d(n); for(int i = 0; i < n; ++i){ for(int j = 1; j < n; ++j){ if(p[i][j] > 0) d.merge(i, j); } } vector<vector<int>> C(n); for(int i = 0; i < n; ++i){ C[d.find(i)].pb(i); } for(auto v: C){ bool ok = solve(v, answer); if(!ok) return 0; } build(answer); return 1; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Too few ways to get from 0 to 1, should be 1 found 0 |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Too few ways to get from 0 to 1, should be 1 found 0 |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 344 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 few ways to get from 1 to 2, should be 1 found 0 |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Too few ways to get from 0 to 1, should be 1 found 0 |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Too few ways to get from 0 to 1, should be 1 found 0 |
3 | Halted | 0 ms | 0 KB | - |