QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#325399 | #7936. Eliminate Tree | javillamip# | WA | 82ms | 31648kb | C++17 | 1.3kb | 2024-02-11 09:41:43 | 2024-02-11 09:41:44 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
#define forn(i,a,n) for(int i=a; i< (int)n; ++i)
#define pb push_back
#define el '\n'
#define d(x) cerr<< #x<< " " << x<<el
#define sz(v) ((int)v.size())
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cout << setprecision(20)<< fixed;
int n; cin>>n;
set<int> g[n];
vi deg(n);
vector<bool> seen(n);
forn(i,0,n - 1){
int u,v; cin>>u>>v;
--u; --v;
g[u].insert(v);
g[v].insert(u);
deg[u]++;
deg[v]++;
}
int start = 0;
forn(i,0,n)if(deg[i] > 1){start = i; break;}
queue<int> q;
q.push(start);
seen[start] = true;
ll ans = 0;
while(sz(q)){
int u = q.front(); q.pop();
int leafs = 0;
for(int v : g[u]){
if(!seen[v]){
seen[v] = true;
if(deg[v] > 1){
q.push(v);
}else leafs++;
}
}
if(leafs > 0){
ans += 2ll * (leafs - 1) + 1ll;
}else ans += 2;
}
cout << ans <<el;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
5 1 2 2 3 3 4 3 5
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
4 1 2 2 3 3 4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 82ms
memory: 31648kb
input:
196666 32025 108673 181779 17115 162570 134230 93003 39673 89144 1269 185919 154408 34896 65369 35860 44720 55698 1390 45520 189805 147867 124511 135459 132555 87303 18031 176314 59695 33352 130640 87272 39716 35749 108807 143493 94486 126512 116598 40212 70895 132216 80855 22241 188737 150354 17346...
output:
211313
result:
wrong answer 1st numbers differ - expected: '138182', found: '211313'