CSES - Datatähti 2018 loppu - Results
Submission details
Task:Tietoverkko
Sender:FSMnArmosta
Submission time:2018-01-18 14:31:43 +0200
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED28
#2ACCEPTED72
Test results
testverdicttimegroup
#1ACCEPTED0.04 s1details
#2ACCEPTED0.05 s1details
#3ACCEPTED0.04 s1details
#4ACCEPTED0.04 s1details
#5ACCEPTED0.04 s1details
#6ACCEPTED0.19 s2details
#7ACCEPTED0.16 s2details
#8ACCEPTED0.14 s2details
#9ACCEPTED0.16 s2details
#10ACCEPTED0.21 s2details

Code

#include <bits/stdc++.h>

using namespace std;

set<pair<int, int> > nonEssential;

vector<int> conn[100000];

int origin[100000];

int n;

int vnum[100000];

int v = 0;

void markLoop(int a, int b){

//  cout << a << " " << b << endl;

  int k = a;
  int k2 = origin[k];
  while(b != k){
    if(k != k2)
      nonEssential.insert({min(k, k2), max(k, k2)});
    k = origin[k];
    k2 = origin[k];
  }
  nonEssential.insert({min(a, b), max(a, b)});

}

void setOrigin(int k){
  v++;
  for(int t : conn[k]){
    if(origin[t] == -1){
      origin[t] = k;
      vnum[t] = v;
      setOrigin(t);
    }else if(origin[k] != t && vnum[k] < vnum[t]){
      markLoop(t, k);
    }
  }
}

int main(){
  cin >> n;
  for(int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    conn[a].push_back(b);
    conn[b].push_back(a);
    origin[i] = -1;
  }
  origin[0] = 0;
  setOrigin(0);
  cout << n - nonEssential.size() << endl;
  /*for(pair<int, int> k: nonEssential){
    cout << k.first+1 << " | " << k.second+1 << endl;
  }*/ 
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
100
16 88
6 77
60 92
98 64
...

correct output
97

user output
97

Test 2

Group: 1

Verdict: ACCEPTED

input
100
97 41
95 93
79 60
5 4
...

correct output
95

user output
95

Test 3

Group: 1

Verdict: ACCEPTED

input
100
87 24
21 49
86 85
42 32
...

correct output
90

user output
90

Test 4

Group: 1

Verdict: ACCEPTED

input
100
30 24
54 79
51 6
80 29
...

correct output
50

user output
50

Test 5

Group: 1

Verdict: ACCEPTED

input
100
11 27
54 59
100 90
2 95
...

correct output
0

user output
0

Test 6

Group: 2

Verdict: ACCEPTED

input
100000
98276 76171
70684 49183
48756 661
17166 16972
...

correct output
99997

user output
99997

Test 7

Group: 2

Verdict: ACCEPTED

input
100000
35903 47275
13566 84
58018 42495
57071 4451
...

correct output
99995

user output
99995

Test 8

Group: 2

Verdict: ACCEPTED

input
100000
79209 94485
60266 86793
27501 19927
13544 59730
...

correct output
99000

user output
99000

Test 9

Group: 2

Verdict: ACCEPTED

input
100000
68402 82703
12892 46068
60013 40753
26168 34434
...

correct output
90000

user output
90000

Test 10

Group: 2

Verdict: ACCEPTED

input
100000
37330 74855
54324 45726
61652 15611
79081 47339
...

correct output
0

user output
0