# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
441675 | Mahfel | Political Development (BOI17_politicaldevelopment) | C++17 | 7 ms | 844 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MXN = 5002;
vector<int> adj[MXN];
int h[MXN];
bool k3,mark[MXN];
void DFS(int v , int dad) {
mark[v] = 1;
h[v] = (dad == -1 ? 0 : h[dad]+1);
vector<int> be;
for(auto u : adj[v]) {
if(mark[u]) {
if(h[u] == h[v]-2) k3 = 1;
be.push_back(h[u]);
continue;
}
DFS(u , v);
}
sort(be.begin() , be.end());
for(int i = 1 ; i < be.size() ; i++) {
if(be[i]-be[i-1] == 1) {
k3 = 1; break;
}
}
}
int main() {
int n,m = 0,k; cin >> n >> k;
for(int i = 0 ; i < n ; i++) {
int d; cin >> d; m += d;
for(int j = 0 ; j < d ; j++) {
int u; cin >> u;
adj[i].push_back(u);
}
}
m /= 2;
for(int i = 0 ; i < n ; i++) {
if(mark[i]) continue;
DFS(i , -1);
}
if(k3) {
cout << "3\n"; return 0;
}
if(m > 0) {
cout << "2\n";
} else {
cout << "1\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |