Submission #173293

#TimeUsernameProblemLanguageResultExecution timeMemory
173293DavidDamianIslands (IOI08_islands)C++11
0 / 100
460 ms131076 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; struct edge{ int to; int w; int id; }; int n; short color[1000006]; stack<edge> S; ll sumCycle; vector<edge> eCycle; vector<int> cycle; vector<edge> adjList[1000006]; void dfsVisit(int u,int id) { color[u]=1; for(edge e: adjList[u]){ int v=e.to; if(id==e.id) continue; if(color[v]==0){ e.to=u; S.push(e); e.to=v; dfsVisit(v,e.id); } else if(color[v]==1){ //Cycle edge x=e; x.to=u; eCycle.push_back(x); x.to=v; x=S.top(); S.pop(); while(x.to!=v){ eCycle.push_back(x); x=S.top(); S.pop(); } eCycle.push_back(x); } } if(S.size()) S.pop(); color[u]=-1; } ll total=0; void dfs() { for(int i=1;i<=n;i++){ if(color[i]==0){ dfsVisit(i,0); //total+=maxPath(i); total+=1; cycle.clear(); } } } int main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; for(int i=1;i<=n;i++){ int a; int b; cin>>a>>b; edge e; e.to=a; e.w=b; e.id=i; adjList[i].push_back(e); e.to=i; adjList[a].push_back(e); } dfs(); cout<<total<<'\n'; return 0; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...