QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#325350#7936. Eliminate Treejavillamip#WA 63ms15784kbC++171.3kb2024-02-11 08:40:102024-02-11 08:40:10

Judging History

你现在查看的是最新测评结果

  • [2024-02-11 08:40:10]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:15784kb
  • [2024-02-11 08:40:10]
  • 提交

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;
  vi g[n];
  vi deg(n);
  forn(i,0,n - 1){
    int u,v; cin>>u>>v; 
    --u; --v;
    g[u].pb(v);
    g[v].pb(u);
    deg[u]++;
    deg[v]++;
  }
  
  vector<bool> seen(n);
  queue<int> q;
  forn(i,0,n){
    if(deg[i] == 1){
      q.push(i);
      seen[i] = true;
    }
  }
  ll ans = 0;
  vi cnt(n);
  while(sz(q)){
    int u = q.front(); q.pop();
    for(int v : g[u]){
      if(!seen[v]){
        seen[v] = true;
        q.push(v);
      }
      if(deg[u] == 1)cnt[v]++;
    }
  }
  forn(i,0,n){
    if(cnt[i] > 0)ans += 2ll * cnt[i] - 1ll;
    else if(deg[i] > 1)ans+=2;
  }
  cout << ans <<el;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3848kb

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: 3612kb

input:

4
1 2
2 3
3 4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 63ms
memory: 15784kb

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'