SuryaManikanta's blog

By SuryaManikanta, history, 18 months ago, In English

link: https://cses.fi/problemset/task/1681/ mycode:

 #include<bits/stdc++.h>
 using namespace std;
 #define SPEED() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 #define ll long long 
 #define MOD 1000000007

vector<ll> topo;
vector<ll> vis (1e5+1);

void dfs(ll x,vector<vector<ll>> adj){
  if(vis[x]){
    return;
  }
  vis[x]=1;
  for(auto ele:adj[x]){
    dfs(ele,adj);
  }
  
  topo.push_back(x);
}

 
 
 int main(){
     ll n,m;cin>>n>>m;
     vector<vector<ll>> adj (n+1);
     vector<vector<ll>> rev (n+1);
     
     ll a,b,ans=0;
     for(int i=0;i<m;i++){
      cin>>a>>b;
      adj[a].push_back(b);
      rev[b].push_back(a);
     }
    vector<ll> dp (n+1);
    dp[1]=1;
   dfs(1,adj);
    // for(auto ele:topo)
    //   cout<<ele<<" ";

reverse(topo.begin(),topo.end());
// for(auto ele: topo)
// cout<<ele<<" ";

    for(auto ele:topo){
      if (ele>1)
      {
         for(auto elee:rev[ele]){
       
          dp[ele]+=dp[elee];
          dp[ele]%=MOD;
       
      }
      }
     
    }

    cout<<dp[n]<<endl;
    // for(int i=1;i<=n;i++){
    //   cout<<dp[i]<<endl;
    // }


 }

getting runtime error for large inputs.

Full text and comments »

  • Vote: I like it
  • -8
  • Vote: I do not like it

By SuryaManikanta, history, 22 months ago, In English

Yesterday, I gave codeforces round 801. I read first problem, I am the guy who expects clear problem statements any how I end up skipping first problem(I solved it later after contest dedicating 5 min for reading clearly and understand the problem),We do expect a clean and neat problem statement. Went ahead to solve problem B It's my fault I read the question wrong(Mike starts picking always from pile 1, I have not noticed that and solved for problem where Mike can start with any pile) My wrong observation code passed Test cases, So they can take some time and design sample test cases in a way such that many can clear their doubts about the problem from them(although I agree they can't show a way to solve the problem but adding few extra cases which don't direct to solution will definitely help readers/solvers to get good idea of the problem and avoids many mistakes.

Full text and comments »

  • Vote: I like it
  • +11
  • Vote: I do not like it