Submission #1073719

# Submission time Handle Problem Language Result Execution time Memory
1073719 2024-08-24T19:04:43 Z vjudge1 Simurgh (IOI17_simurgh) C++17
0 / 100
1 ms 348 KB
#include "simurgh.h"
#include <bits/stdc++.h>

using namespace std;

vector<vector<pair<int,int>>>adj(505);
vector<vector<int>>adj1(505);
vector<bool> vis(505,0);
vector<int> r;

void DFS(int n){
    vis[n] = 1;

    for(auto [x,y]: adj[n]){
        if(vis[x])continue;
        r.push_back(y);
        DFS(x);
    }
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	vector<pair<int,int>> edges;
	int res=0;
	for(int i=0; i < u.size(); i++){
        edges.push_back({u[i],v[i]});
        adj[u[i]].push_back({v[i],i});
        adj[v[i]].push_back({u[i],i});
	}
	DFS(0);
	/*for(auto x: r){
        cout<<x<<" ";
	}
	cout<<endl;*/

	int pos=0, lastres = 0, last = 0;
    vector<bool> used(edges.size(),0);
    for(auto x: r){
        used[x] = 1;
    }
    res = count_common_roads(r);
    while(pos < n-1 && res < n-1){
        for(auto [x,y]: adj[edges[r[pos]].second]){
            if(!used[y]){
                last = r[pos];
                r[pos] = y;
                used[y] = 1;
                break;
            }
        }
        lastres = res;
        res = count_common_roads(r);
        /*for(auto x: r){
            cout<<x<<" ";
        }
        cout<<endl;*/
        if(lastres < res){
            pos++;
        }else if(lastres == res){
            for(auto [x,y]: adj[edges[r[pos]].first]){
                used[y] = 1;
            }
            for(auto [x,y]: adj[edges[r[pos]].second]){
                used[y] = 1;
            }
            used[r[pos]] = 0;
            r[pos] = last;
            pos++;
            res = lastres;
        }else if(lastres > res){
            r[pos] = last;
            pos++;
            res = lastres;
        }
    }
    return r;

	/*for(int b=0; b < (1<<edges.size()); b++){
        r.clear();
        for(int i=0; i < n; i++){
            adj1[i].clear();
            vis[i] = 0;
        }

        for(int i=0; i < edges.size(); i++){
            if(b & (1<<i)){
                adj1[edges[i].first].push_back(edges[i].second);
                adj1[edges[i].second].push_back(edges[i].first);
                r.push_back(i);
            }
        }
        if(r.size() != n-1){
            continue;
        }

        DFS(0);
        int cnt = 0;
        for(int i=0; i < n; i++){
            if(vis[i]){
                cnt++;
            }else{
                break;
            }
        }

        if(cnt == n){
            res = count_common_roads(r);
        }else{
            continue;
        }

        if(res == n-1){
            return r;
        }
	}*/

	return {0};
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:24:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for(int i=0; i < u.size(); i++){
      |               ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB correct
2 Incorrect 0 ms 348 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB WA in grader: NO
2 Halted 0 ms 0 KB -