Submission #423551

#TimeUsernameProblemLanguageResultExecution timeMemory
423551AmylopectinHotspot (NOI17_hotspot)C++14
100 / 100
313 ms1320 KiB
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
const int mxn = 10010,mxi = 1e9 + 10;
queue <int> qu;
vector <int> pa[mxn] = {};
int di[mxn] = {},u[mxn] = {};
double psu[mxn] = {},npa[mxn] = {},rdi[mxn] = {};
int main()
{
    int i,j,n,m,f,t,cdi,fdi,fn,cn,q,k,stn,enn,su,cou;
    double cma,df,dt;
    scanf("%d %d",&n,&m);
    for(i=0; i<m; i++)
    {
        scanf("%d %d",&f,&t);
        pa[f].push_back(t);
        pa[t].push_back(f);
    }
    scanf("%d",&q);
    for(i=0; i<q; i++)
    {
        scanf("%d %d",&stn,&enn);
        qu.push(stn);
        for(j=0; j<n; j++)
        {
            di[j] = mxi;
            npa[j] = 0;
            rdi[j] = 0;
        }
        npa[stn] = 1;
        di[stn] = 0;
        while(!qu.empty())
        {
            cn = qu.front();
            if(cn == enn)
            {
                break;
            }
            qu.pop();
            for(j=0; j<pa[cn].size(); j++)
            {
                fn = pa[cn][j];
                if(di[fn] < di[cn]+1)
                {
                    continue;
                }
                if(npa[fn] == 0)
                {
                    npa[fn] += npa[cn];
                    di[fn] = di[cn] + 1;
                    qu.push(fn);
                }
                else
                {
                    npa[fn] += npa[cn];
                }
            }
        }
        while(!qu.empty())
        {
            qu.pop();
        }
        qu.push(enn);
        dt = npa[enn];
        rdi[enn] = npa[enn];
        while(!qu.empty())
        {
            cn = qu.front();
            df = rdi[cn];
            psu[cn] += df / dt;
//            if(cn == enn)
//            {
//                break;
//            }
            qu.pop();
//            cu = 0;
            for(j=0; j<pa[cn].size(); j++)
            {
                fn = pa[cn][j];
//                if(di[fn] + 1 == di[cn] && u[fn] == i+1)
//                {
//
//                }
                if(di[fn] + 1 == di[cn])
                {
                    rdi[fn] += (npa[fn] / npa[cn]) * rdi[cn];
                }
                if(di[fn] + 1 == di[cn] && u[fn] != i+1)
                {
                    u[fn] = i+1;
                    qu.push(fn);
                }
//                if(di[fn] == di[cn] + 1)
//                {
//                    if(u[fn] == i+1)
//                    {
//                        cou ++;
//                    }
//                }
//                if(di[fn] < di[cn]+1)
//                {
//                    continue;
//                }
//                if(npa[fn] == 0)
//                {
//                    npa[fn] += npa[cn];
//                    di[fn] = di[cn] + 1;
//                    qu.push(fn);
//                }
//                else
//                {
//                    npa[fn] += npa[cn];
//                }
            }
//            npa[fn] *= cou;
//            df = npa[fn];
//            psu[cn] += df / dt;
        }
    }
    cma = -1;
    cn = -1;
    for(i=0; i<n; i++)
    {
        if(psu[i] > cma)
        {
            cn = i;
            cma = psu[i];
        }
    }
    printf("%d\n",cn);
    return 0;
}

Compilation message (stderr)

hotspot.cpp: In function 'int main()':
hotspot.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             for(j=0; j<pa[cn].size(); j++)
      |                      ~^~~~~~~~~~~~~~
hotspot.cpp:80:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |             for(j=0; j<pa[cn].size(); j++)
      |                      ~^~~~~~~~~~~~~~
hotspot.cpp:13:21: warning: unused variable 'cdi' [-Wunused-variable]
   13 |     int i,j,n,m,f,t,cdi,fdi,fn,cn,q,k,stn,enn,su,cou;
      |                     ^~~
hotspot.cpp:13:25: warning: unused variable 'fdi' [-Wunused-variable]
   13 |     int i,j,n,m,f,t,cdi,fdi,fn,cn,q,k,stn,enn,su,cou;
      |                         ^~~
hotspot.cpp:13:37: warning: unused variable 'k' [-Wunused-variable]
   13 |     int i,j,n,m,f,t,cdi,fdi,fn,cn,q,k,stn,enn,su,cou;
      |                                     ^
hotspot.cpp:13:47: warning: unused variable 'su' [-Wunused-variable]
   13 |     int i,j,n,m,f,t,cdi,fdi,fn,cn,q,k,stn,enn,su,cou;
      |                                               ^~
hotspot.cpp:13:50: warning: unused variable 'cou' [-Wunused-variable]
   13 |     int i,j,n,m,f,t,cdi,fdi,fn,cn,q,k,stn,enn,su,cou;
      |                                                  ^~~
hotspot.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
hotspot.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%d %d",&f,&t);
      |         ~~~~~^~~~~~~~~~~~~~~
hotspot.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
hotspot.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d %d",&stn,&enn);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...