# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
792088 | kwongweng | Newspapers (CEOI21_newspapers) | C++17 | 1 ms | 340 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;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define fi first
#define se second
vi g[1001];
vi d(1001), mxd(1001), p(1001);
// mxd[u] - max d[v] for v in subtree u
void dfs(int u){
mxd[u] = d[u];
for (int v : g[u]){
if (p[u]==v) continue;
p[v] = u; d[v]=d[u]+1;
dfs(v);
mxd[u] = max(mxd[u], mxd[v]);
}
}
void solve(){
int n, m; cin >> n >> m;
FOR(i,0,m){
int u, v; cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
if (m>n-1){
cout << "NO\n";
return;
}
FOR(u,1,n+1){
FOR(i,1,n+1){
d[i]=0; p[i]=0; mxd[i]=0;
}
dfs(u);
int cnt = 0;
for (int v : g[u]){
if (mxd[v] >= 3){
cnt++;
}
}
if (cnt >= 3){
cout << "NO\n";
return;
}
}
cout << "YES\n";
}
int main(){
ios::sync_with_stdio(false);
if (fopen("input.txt", "r")) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int TC = 1;
//cin >> TC;
FOR(i, 1, TC+1){
//cout << "Case #" << i << ": ";
solve();
}
return 0;
}
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... |