Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#pragma GCC optimize("Ofast")
- //#pragma GCC target("avx,avx2,fma")
- //#pragma GCC optimization ("unroll-loops")
- #include<bits/stdc++.h>
- #include<string.h>
- using namespace std;
- #define pb push_back
- #define all(v) v.begin(),v.end()
- #define yes cout<<"YES"<<endl;
- #define no cout<<"NO"<<endl;
- #define ff first
- #define sc second
- #define inf 999999999
- #define pi 3.14159265359
- #define printv(v) for(auto x:v)cout<<x<<' ';cout<<endl;
- #define takev(v) for(auto &x:v)cin>>x;
- inline int random(int a=1,int b=10)
- {
- return a+rand()%(b-a+1);
- }
- typedef long long ll;
- inline ll lcm(ll a,ll b)
- {
- return (a*b)/__gcd(a,b);
- }
- //#define see(x) cout<<endl<<#x<<" : "<<(x)<<endl;
- #define see(args...) \
- { \
- string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
- stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);\
- }
- void err(istream_iterator<string> it) {}
- template<typename T, typename... Args>
- void err(istream_iterator<string> it, T a, Args... args)
- {
- cout<< *it << " = " << a <<",\n"[++it==istream_iterator<string>()];
- err(it, args...);
- }
- #define scc(n) scanf("%d",&n);
- #define sccc(n) scanf("%lld",&n);
- typedef pair<ll,ll> pll;
- typedef pair<int,int> pii;
- const int N=1e5+9,mod=1e9+7;
- int main()
- {
- // ios::sync_with_stdio(0);
- // cin.tie(NULL);
- int _ = 0;
- while(true)
- {
- int x,y;
- scc(x)
- scc(y)
- if(!x)break;
- set<int>s;
- vector< pii > v;
- vector< int >change(102);
- v.pb({x,y});
- s.insert(x);
- s.insert(y);
- change[x] = x;
- change[y] = y;
- while(true)
- {
- scc(x)
- scc(y)
- if(!x)break;
- v.pb({x,y});
- s.insert(x);
- s.insert(y);
- change[x] = x;
- change[y] = y;
- }
- int nodes = s.size();
- int cur = 1;
- for(auto x:s)
- {
- if(cur == x)
- {
- cur++;
- continue;
- }
- change[x] = cur;
- cur++;
- }
- vector< vector<int> > G(101,vector<int>(101,inf));
- for(int i=1;i<=nodes;i++)G[i][i] = 0;
- for(auto [l,r] : v)
- {
- G[change[l]][change[r]] = 1;
- }
- for(int k=1;k<=nodes;k++)
- {
- for(int i=1;i<=nodes;i++)
- {
- for(int j=1;j<=nodes;j++)
- {
- if(G[i][j] > G[i][k] + G[k][j]) G[i][j] = G[i][k] + G[k][j];
- }
- }
- }
- double total = 0;
- double total_pairs = nodes*(nodes-1);
- for(int i=1;i<=nodes;i++)
- {
- for(int j=1;j<=nodes;j++)
- {
- total += G[i][j];
- }
- }
- printf("Case %d: average length between pages = %.3lf clicks\n",++_,total/total_pairs);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement