Submission #173293

# Submission time Handle Problem Language Result Execution time Memory
173293 2020-01-03T17:55:04 Z DavidDamian Islands (IOI08_islands) C++11
0 / 100
460 ms 131076 KB
#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 time Memory Grader output
1 Incorrect 23 ms 23804 KB Output isn't correct
2 Incorrect 23 ms 23800 KB Output isn't correct
3 Incorrect 23 ms 23928 KB Output isn't correct
4 Incorrect 23 ms 23800 KB Output isn't correct
5 Incorrect 23 ms 23800 KB Output isn't correct
6 Incorrect 23 ms 23800 KB Output isn't correct
7 Incorrect 23 ms 23800 KB Output isn't correct
8 Incorrect 23 ms 23800 KB Output isn't correct
9 Incorrect 23 ms 23800 KB Output isn't correct
10 Incorrect 23 ms 23800 KB Output isn't correct
11 Incorrect 22 ms 23800 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 23928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 24824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 28872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 119 ms 35080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 196 ms 45028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 380 ms 68884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 460 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -