Submission #1130837

#TimeUsernameProblemLanguageResultExecution timeMemory
1130837mnbvcxz123Programming Contest (POI11_pro)C++20
100 / 100
451 ms10396 KiB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define taskname "A"
#define pb	push_back
#define mp 	make_pair


typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
typedef tree <ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 500 + 5;
const int inf = 1e6;

struct edge{
    int u , v , c;
    edge(){};edge(int u , int v , int c):u(u),v(v),c(c){};
}e[maxn * maxn * 2];

vector<int> adj[maxn * 2];

int nTime = 0 , s , t;

void add_edge(int u , int v , int c){
    e[nTime * 2] = edge(u,v,c);
    e[nTime * 2 + 1] = edge(v,u,0);
    adj[u].pb(nTime * 2);adj[v].pb(nTime*2+1);
    ++nTime;
}

int d[maxn * 2];
int trace[maxn * 2];
bool vis[maxn * 2];

bool spfa(){
    queue<int> q;
    fill_n(d,maxn*2,inf);fill_n(trace,maxn*2,-1);
    q.push(s);
    d[s] = 0;
    while(q.size()){
        auto u = q.front();q.pop();vis[u] = 0;
        for(int c : adj[u]){
            if(e[c].c > 0 && d[e[c].v] > 0){
                d[e[c].v] = 0;
                trace[e[c].v] = c;
                if(vis[e[c].v] == 0){
                    vis[e[c].v] = 1;
                    q.push(e[c].v);
                }
            }
        }
    }
    return d[t] != inf;
}

int n , m , R , T , K;
ii a[maxn * maxn];
int deg[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin);
        freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> m >> R >> T >> K;
    s = 0 , t = n + m + 1;
    for(int i = 1 ; i <= K ; ++i){
        int u, v;cin >> u >> v;
        a[i] = mp(u,v);
        add_edge(u,v+n,1);
    }
    for(int i = 1 ; i <= m ; ++i){
        add_edge(i + n , t , 1);
    }
    for(int i = 1 ; i <= n ; ++i){
        add_edge(s , i , 1);
    }
    int res1 = 0, res = 0;
    for(int j = 1 ; j * R <= T && res1 < m ; ++j){
        for(int i = 0 ; i < n ; ++i){
            e[(i + K + m) * 2].c = 1;
            e[(i + K + m) * 2 + 1].c = 0;
        }
        while(spfa()){
            int delta = 1;
            for(int u = t ; u != s ; u = e[trace[u]].u){
                e[trace[u]].c -= delta;e[trace[u]^1].c += delta;
            }
            res += j;
            res1++;
        }
    }
    cout << res1 << " " << (ll)res * R << '\n';
    for(int i = 1 ; i <= K ; ++i){
        if(e[(i - 1) * 2].c == 0){
            cout << a[i].first << " " << a[i].second << " " << R * deg[a[i].first]++ << '\n';
        }
    }
}

Compilation message (stderr)

pro.cpp: In function 'int main()':
pro.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(taskname".INP", "r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
pro.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(taskname".OUT", "w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...