답안 #1073713

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1073713 2024-08-24T18:55:09 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);

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

    for(auto x: adj1[n]){
        if(vis[x])continue;
        DFS(x);
    }
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	vector<pair<int,int>> edges;
	vector<int> r;
	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});
	}
	for(auto [x,y]: adj[0]){
        r.push_back(y);
        //cout<<y<<" ";
	}
	//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:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int i=0; i < u.size(); i++){
      |               ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB WA in grader: NO
2 Halted 0 ms 0 KB -